



/*----------------------------------------------------------------------------------------
当前实现的命令

#if 0
3.2  读取白名单  readWhiteList
3.4  读取分组名称数量 readGroupNameNum 
3.5  读取分组 readGroup	16
3.7  配置场景  setScence	18
3.8  读取场景  readScence	20
3.9  配置绑定  setBind	21
3.10  读取绑定  readBind	22

3.14  读网关信息  readGwMsg	34
3.15  设置网关  setupGw	35
3.16  读网关配置 readGwSetup	36
3.17  读白名单在网设备 readOnlineInList	37
3.18  读非白名单在网设备 readOnlineNoList	38


3.20  重启网关  resetGw	40
////3.21  删除白名单  delWhiteList	40
3.22  外部信号输入 extenalSignal	41
////3.23  删除场景 delScence	41
////3.24  执行场景 execScence	42
3.25  读取所有绑定列表 readBindAllHead	42
////3.26  绑定删除   bindDel	43
3.27 读取设备pid：   readPid	43
3.28  同步场景数据   syncScene	44

3.32   读取主平台ip端口  mainIpRead	47
3.33  设置主平台ip端口   mainIpSet	47
3.35  读取网关io状态      gwIoRead	48
3.36  设置网关io（继电器） 状态  gwIoSet	49
3.36.1   全部output同时设	49
3.36.2    指定设置某个或某几个output	49
3.37  读取定时任务    timingTaskRead	50
3.38  设置定时任务   timingTaskSet	51
3.39  读取网关以太网ip信息  gwEthIpRead	52
3.40  设置网关以太网ip信息  gwEthIpSet	52
3.41  读取网关网络状态信息  gwIfconfigRead	53

#endif





#if 0
3，下行指令详述
json项为 cmd， value为各个命令字符串。需要应答， 应答json项为response。
“head”项是固定的，不同指令间是”指令类型”的区别：
cmd/response/notify/indicate/confirm 五选一。
下面的head项陈述，可能只写”指令类型”，而忽略其他的固定项。
“body”,”data”,”attrLst”是有效数据。

3.1  配置白名单  setWhiteList
3.1.1 下行命令:
{
“head”:{
  “gatewayId”:”xxxxxx”,      // 消息来源或目的设备
  “msgId”:12345,           // 消息序列号
  “timeStamp”:12345678,    // unix 时间
  “cmd”:”setWhiteList”      // 指令类型为：cmd
},
“body”:[
{ "name":"lamp1",            //  灯的名称， 用户输入的， 不同设备不可同名。
           "mac":"112233445566",  // 灯mac地址， 固定的，用户扫描或手动输入
           “nodeType”:0,
           “channel”:1,
           “privAddr”:23,
           "pid": "xxxxxx",       // 产品类别， 平台预先定好的
           “model”:”NBE_32LE5B”, // 产品型号， 可选
          “propertyId”:2,                    // 资产id（灯杆号）， 可选
          “propertyName”:”abcdfegggg”       //  资产名称， 可选
          “mainGroupNo”:3,                // 路灯分组号， 可选
          “label”:”xxx”                  // 标签（别名），可选，不同设备可以同名，默认同name
}
]
}

#endif 


#if 0

兼容mqtt， tcp， udp， 串口通讯。
tcp， udp 指定ip， 端口号；串口指定串口号， 波特率；mqtt指定ip， 端口号，1个指令使用一个topic。数据包的功能由“cmd”字段决定。暂未使用加密传输。网关采用udp广播自动发现主机。字符串只支持ASC码和GB2313，不支持UTF8。

提示：本文档为内部开发文档，只为阐述清楚实现逻辑，未对文字进行校对，可能有字符的错误或遗落。 特别是json格式数据，请以正常json格式为准。

1.1 数据包简要解析
数据包由head和body以及其他一些项组成，head指示包的来源目的，功能，时间戳等信息。body是有效数据。例子如下：
{
“head”:{
   “replaceId”:”gw_000011112222”,  // 消息目的地/消息来源地 识别码
  “gatewayId”:”xxxxxx”,      // 消息相关的网关编号
  “msgId”:12345,           // 消息序列号
  “timeStamp”:12345678,    // unix 时间
  “cmd”:”setWhiteList”      // 指令类型
},
“body”:[                 // body 表示数组
{
    "name":"lamp1",            //  灯的名称， 用户输入的
    "mac":"112233445566",  // 灯mac地址， 固定的，用户扫描或手动输入
    "pid": "xxxxxx",                // 产品类别， 平台预先定好的
}
],
“data”:{                       // data 表示单项json
   “item1”:”1234”
}
}
实际发出的数据包最后加一字节’\n’作为结束符。

head项解析：
replaceId ：
当消息是网关发出时， 表示数据目的id。
当消息是发给网关的， 则表示数据来源id。
作为来源时， 是唯一标识字符串。
作为目的时，可以表示广播，组播，和定点发送。
广播是发给所有连接设备。字符串长度为0时表示广播。
 组播则是分类发送，有 platform， mobile（小程序或app），panel（中控屏）3类。

#endif

-------------------------------------------------------------------------------------------------------------------------------- */



//  gcc ./cJSON/cJSON.c cjson_test.c -o 1  -lm
//  gcc cJSON.c cjson_test.c -o cjson_test  -lm



#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#include "dev_DIDO.h"
#include "dev_ac_meter.h"
#include "dev_air_cond.h"
#include "dev_battery.h"
#include "dev_dc_meter.h"

#include "dev_generator.h"

#include "dev_liquid_level.h"
#include "dev_manager.h"
#include "dev_smoke.h"
#include "dev_temper.h"
#include "dev_water.h"
#include "iot_node.h"
#include "iot_node_func.h"
#include "iotv30_config.h"
#include "meter.h"
#include "print_log.h"  


#include "cJSON.h"
#include "gui_logist.h"

#include "proto_plat.h"
#include "string_tools.h"
#include "gw_ktj_tcp_client.h"
#include "device_data_struct.h"


#include "tcp_api_01.h" 
//#include "iotv30_tcp_client.h" 

#include "gui_cjson_api.h"


#include "cjson_api_readAttr.h"

#include "uart_printf.h"




void json_read_cmd_with_data(const char* data_str )
{

}



//3.12  读属性  readAttr  
//void json_read_cmd_with_data(const char* cmd_str,const char* cct_id_str,const int msg_id );

void json_readAttr( void )
{
 char data_str[] ="beijinghuanyingni";

	 //json_read_cmd("readAttr", "", gui_js_api_msg_id++ );    ////3.14  读网关信息  readGwMsg	34
      json_read_cmd_with_data( data_str  );
}




	// 	"mac": "FFFFFFFFFFFF",   //  12个ff可以不发
	// 	"nodeType": 1,
	// 	"channel": 1,
	// 	"name": "dev041",    // 可以不要
	// 	"privAddr": 55
    //读单个设备的所有属性
void json_readAttr_single(uint8_t dev_addr, uint8_t channel,uint8_t nodeType )
{
    cJSON* cjs_root = NULL;  
    cJSON* cjs_head = NULL;
    cJSON* cjs_data = NULL;

    char*  cjs_str  = NULL;

 //   char  enter_code  = 0x0A;   /////ver.1.38  '\n'
   // char  enter_code  = '\n';   /////ver.1.39  '\n'   0x0A;


	//printf("%s,cmd=%s,data=%s\n",__FUNCTION__,cmd_str,data_str);		//输出字符串

	cjs_root = cJSON_CreateObject();   //创建一个对象
    if (cjs_root == NULL)
    {
        goto lab_exit;
    }

	cjs_head = cJSON_CreateObject();   //创建一个对象
    if (cjs_head == NULL)
    {
        goto lab_exit;
    }


	cjs_data = cJSON_CreateObject();   //创建一个对象
    if (cjs_data == NULL)
    {
        goto lab_exit;
    }


////---------------head 部分-----------------------------------------------

//“head”:{
////   “replaceId”:”gw_000011112222”,  // 消息目的地/消息来源地 识别码	
//  “gatewayId”:”xxxxxx”,      // 消息来源或目的设备
//  “msgId”:12345,           // 消息序列号
//  “timeStamp”:12345678,    // unix 时间
//  “cmd”:readAttr      // 指令类型为：cmd
//},


// 组播则是分类发送，有 platform， mobile（小程序或app），panel（中控屏）3类。
//replaceId	平台	手机	面板
//字符串	“platform”	“mobile”	“panel”

#if  0

	cJSON_AddStringToObject(cjs_head,	"replaceId",	"panel" );	

//	cJSON_AddStringToObject(cjs_head,	"cmd",	"readAttr" );	
	cJSON_AddStringToObject(cjs_head,	"cmd",	cmd_str );		
	cJSON_AddStringToObject(cjs_head,	"gatewayId",	cct_id_str );	//添加字符串 

	cJSON_AddNumberToObject(cjs_head,	"msgId",	msg_id );	//添加整型数字
//	cJSON_AddNumberToObject(cjs_head,	"msgId",	gui_js_api_msg_id++);	//添加整型数字

	cJSON_AddNumberToObject(cjs_head,	"timeStamp",	gui_js_api_timeStamp);

	cJSON_AddItemToObject(cjs_root,	"head",	cjs_head );	//对象

#else

	set_json_comm_item(cjs_root, TYPE_CMD, "readAttr", gui_js_api_msg_id++ );  // gui_msg_id++

#endif


dev_mod_info_t dev_mod_info ;
uint8_t index = 0 ;

dev_mod_info.chan_addr = dev_addr;
dev_mod_info.channel   = channel;
dev_mod_info.node_type = 0;

//返回 0=查找失败， !0= 查找成功
  if( iot_find_node_index_with_info( &dev_mod_info, &index ) )
  {
     dev_mod_info.node_type = iot_get_node_type_with_index(index);
  }




////---------------data 部分-----------------------------------------------


	// "data": {
	// 	"mac": "FFFFFFFFFFFF",   //  12个ff可以不发
	// 	"nodeType": 1,
	// 	"channel": 1,
	// 	"name": "dev041",    // 可以不要
	// 	"privAddr": 55
    //"mask":"01"
    //"classMask":"11"
	// }


	cJSON_AddNumberToObject(cjs_data,	"privAddr",	dev_addr);
	cJSON_AddNumberToObject(cjs_data,	"channel",	channel);
	cJSON_AddNumberToObject(cjs_data,	"nodeType",	nodeType);

   if( (IOT_SENSOR_smoke !=dev_mod_info.node_type ) && (IOT_SENSOR_water !=dev_mod_info.node_type ) )  // 
   {
        cJSON_AddStringToObject(cjs_data,	"mask",	"01");
        cJSON_AddStringToObject(cjs_data,	"classMask",	"11");  //ver.1.49 由11改为91
   }


	//cJSON_AddNumberToObject(cjs_data,	"name",	"rs-485sensor");
    //cJSON_AddNumberToObject(cjs_data,	"deviceName",	"rs-485sensor");
    
	//cJSON_AddNumberToObject(cjs_data,	"mac",	"FFFFFFFFFFFF");

    cJSON_AddItemToObject(cjs_root,	"data",	cjs_data);	//对象


    //JSON数据结构转换为JSON字符串
#if CJSON_PRINT_UNFORM_ENABLE
	cjs_str = cJSON_PrintUnformatted(cjs_root);    //没有空格符的格式=====提高通信效率------
#else
	cjs_str = cJSON_Print(cjs_root);		         // 有空格符的格式------便于人工阅读识别-------------
#endif



    if (cjs_str == NULL)
    {
        goto lab_exit;
    }

#if CJSON_PRINT_ENABLE
	printf("%s\n",cjs_str);		//输出字符串
#endif		//输出字符串到显示屏------已经在socket那里有打印，这里不再打印

	//send(cjs_str);      //发送数据
    
    //返回值 0---发送失败，1---发送成功
    gw_ktj_TCP_ClientSend( (uint8_t*)cjs_str, strlen(cjs_str) );
  //  gw_ktj_TCP_ClientSend( (uint8_t*)&enter_code, 1 );    //////////ver.1.38-----不知道搞什么飞机，需要加回车结束

   ///// free(cjs_str );   //释放内存空间---尚未确定是否需要这步---????-----不使用---避免内存泄漏-----------debug----2025-03-03--这里没有释放内存----
   cJSON_free(cjs_str ); 

lab_exit:

    if ( cjs_root != NULL)
    {
	    cJSON_Delete(cjs_root);		//清除结构体
    }

    cjs_root = NULL;  
    cjs_str = NULL;

}








	// 	"mac": "FFFFFFFFFFFF",   //  12个ff可以不发
	// 	"nodeType": 1,
	// 	"channel": 1,
	// 	"name": "dev041",    // 可以不要
	// 	"privAddr": 55
    //读单个设备的所有属性
	//(	"mask",	"01");
	//(	"classMask",	"11");

void json_readAttr_single_with_mask(uint8_t dev_addr, uint8_t channel,uint8_t nodeType,char* mask_str, char* class_mask_str )
{
    cJSON* cjs_root = NULL;  
    cJSON* cjs_head = NULL;
    cJSON* cjs_data = NULL;

    char*  cjs_str  = NULL;

    //char enter_code='\n';
   // char enter_code=0x0A;

	//printf("%s,cmd=%s,data=%s\n",__FUNCTION__,cmd_str,data_str);		//输出字符串

	
	cjs_root = cJSON_CreateObject();   //创建一个对象
    if (cjs_root == NULL)
    {
        goto lab_exit;
    }

	cjs_head = cJSON_CreateObject();   //创建一个对象
    if (cjs_head == NULL)
    {
        goto lab_exit;
    }


	cjs_data = cJSON_CreateObject();   //创建一个对象
    if (cjs_data == NULL)
    {
        goto lab_exit;
    }


////---------------head 部分-----------------------------------------------

//“head”:{
////   “replaceId”:”gw_000011112222”,  // 消息目的地/消息来源地 识别码	
//  “gatewayId”:”xxxxxx”,      // 消息来源或目的设备
//  “msgId”:12345,           // 消息序列号
//  “timeStamp”:12345678,    // unix 时间
//  “cmd”:readAttr      // 指令类型为：cmd
//},


// 组播则是分类发送，有 platform， mobile（小程序或app），panel（中控屏）3类。
//replaceId	平台	手机	面板
//字符串	“platform”	“mobile”	“panel”

#if  0

	cJSON_AddStringToObject(cjs_head,	"replaceId",	"panel" );	

//	cJSON_AddStringToObject(cjs_head,	"cmd",	"readAttr" );	
	cJSON_AddStringToObject(cjs_head,	"cmd",	cmd_str );		
	cJSON_AddStringToObject(cjs_head,	"gatewayId",	cct_id_str );	//添加字符串 

	cJSON_AddNumberToObject(cjs_head,	"msgId",	msg_id );	//添加整型数字
//	cJSON_AddNumberToObject(cjs_head,	"msgId",	gui_js_api_msg_id++);	//添加整型数字

	cJSON_AddNumberToObject(cjs_head,	"timeStamp",	gui_js_api_timeStamp);

	cJSON_AddItemToObject(cjs_root,	"head",	cjs_head );	//对象

#else

	set_json_comm_item(cjs_root, TYPE_CMD, "readAttr", gui_js_api_msg_id++ );  // gui_msg_id++

#endif




////---------------data 部分-----------------------------------------------


	// "data": {
	// 	"mac": "FFFFFFFFFFFF",   //  12个ff可以不发
	// 	"nodeType": 1,
	// 	"channel": 1,
	// 	"name": "dev041",    // 可以不要
	// 	"privAddr": 55
    //"mask":"01"
    //"classMask":"11"
	// }


	cJSON_AddNumberToObject(cjs_data,	"privAddr",	dev_addr);
	cJSON_AddNumberToObject(cjs_data,	"channel",	channel);
	cJSON_AddNumberToObject(cjs_data,	"nodeType",	nodeType);

    if( NULL != mask_str )
    {
	   cJSON_AddStringToObject(cjs_data,	"mask",	mask_str );
    }

    if( NULL != class_mask_str )
    {
	   cJSON_AddStringToObject(cjs_data,	"classMask",	class_mask_str );
    }


	//cJSON_AddNumberToObject(cjs_data,	"name",	"rs-485sensor");
    //cJSON_AddNumberToObject(cjs_data,	"deviceName",	"rs-485sensor");
    
	//cJSON_AddNumberToObject(cjs_data,	"mac",	"FFFFFFFFFFFF");

    cJSON_AddItemToObject(cjs_root,	"data",	cjs_data);	//对象



    //JSON数据结构转换为JSON字符串
#if CJSON_PRINT_UNFORM_ENABLE
	cjs_str = cJSON_PrintUnformatted(cjs_root);    //没有空格符的格式=====提高通信效率------
#else
	cjs_str = cJSON_Print(cjs_root);		         // 有空格符的格式------便于人工阅读识别-------------
#endif


    if (cjs_str == NULL)
    {
        goto lab_exit;
    }


#if CJSON_PRINT_ENABLE
	printf("%s\n",cjs_str);		//输出字符串
#endif		//输出字符串到显示屏------已经在socket那里有打印，这里不再打印

	//send(cjs_str);      //发送数据
    
    //返回值 0---发送失败，1---发送成功
    gw_ktj_TCP_ClientSend( (uint8_t*)cjs_str, strlen(cjs_str) );
   // gw_ktj_TCP_ClientSend(uint8_t*)&enter_code, 1 );/////ver.1.41-----

   cJSON_free(cjs_str ); 

lab_exit:

    if ( cjs_root != NULL)
    {
	    cJSON_Delete(cjs_root);		//清除结构体
    }

    cjs_root = NULL;  
    cjs_str = NULL;

}






//,  读一个属性：
//	"head": {
//		"gatewayId": "gw_0000C0A8011B",
//		"msgId": 0,
//		"timeStamp": 1689063160,
//		"cmd": "readAttr"
//	},
//	"data": {
//		"mac": "FFFFFFFFFFFF",
//		"nodeType": 1,
//		"channel": 2,
//		"privAddr": 1,
//		"attrStart": "thOlL",      //  属性名
//		"attrNum": 1           // 固定为1   
//	}
//
//

    //读单个设备的几个属性
void json_readAttr_single_num_by_dpid(uint8_t dev_addr, uint8_t channel,uint8_t nodeType,uint8_t dpid_num,  uint32_t* dpid_buf )
{
    cJSON* cjs_root = NULL;  
    cJSON* cjs_head = NULL;
    cJSON* cjs_data = NULL;
    cJSON* cjs_body = NULL;

    char*  cjs_str  = NULL;


	//printf("%s,cmd=%s,data=%s\n",__FUNCTION__,cmd_str,data_str);		//输出字符串

	
	cjs_root = cJSON_CreateObject();   //创建一个对象
    if (cjs_root == NULL)
    {
        goto lab_exit;
    }

	cjs_head = cJSON_CreateObject();   //创建一个对象
    if (cjs_head == NULL)
    {
        goto lab_exit;
    }


	cjs_data = cJSON_CreateObject();   //创建一个对象
    if (cjs_data == NULL)
    {
        goto lab_exit;
    }


	cjs_body = cJSON_CreateArray();		//创建一个数组  cjs_attrLst
    if (cjs_body == NULL)
    {
        goto lab_exit;
    }


////---------------head 部分-----------------------------------------------

	set_json_comm_item(cjs_root, TYPE_CMD, "readAttr", gui_js_api_msg_id++ ); 


// {"head":{"gatewayId":"gw_0000C0A8011B","msgId":44,"cmd":"readAttr"},"data":{"privAddr":17,"channel":1,"nodeType":1},"body":[{"dpid":43521},{"dpid":43900},{"dpid":44300},{"dpid":44700},{"dpid":45100},{"dpid":45300}]}
// iotv30  socket send done
// 10:07:00- ETH_1 local_ktj_js Rx: len=434
// {"head":{"gatewayId":"gw_0000C0A8011B","replaceId":"","msgId":44,"timeStamp":1747879620,"response":"readAttr"},"data":{"nodeType":1,"channel":1,"privAddr":17,"mac":"FFFFFFFFFFFF","name":"sensor_ch1_addr17","pid":"d003"},"attrLst":[{"dpid":43521,"val":10694,"type":0},{"dpid":43900,"val":3000,"type":0},{"dpid":44300,"val":0,"type":0},{"dpid":44700,"val":259,"type":0},{"dpid":45100,"val":0,"type":0},{"dpid":45300,"val":0,"type":0}]}

////---------------data 部分-----------------------------------------------

// {
// 	"head": {
// 		"gatewayId": "gw_1C32830085B0",
// 		"msgId": 0,
// 		"cmd": "readAttr"
// 	},
// 	"data": {
// 		"nodeType": 1,
// 		"channel": 2,
// 		"privAddr": 1,
// 	},
// 	"body":[
// 	  {"dpid":10001},
// 	  {"dpid":10023}
// 	 ]  
// }


	cJSON_AddNumberToObject(cjs_data,	"privAddr",	dev_addr);
	cJSON_AddNumberToObject(cjs_data,	"channel",	channel);
	cJSON_AddNumberToObject(cjs_data,	"nodeType",	nodeType);

    cJSON_AddItemToObject(cjs_root,	"data",	cjs_data);	//对象


       cJSON *cjs_Z[pb_65H_read_type_0_iot_id_MAX] ;

       if( dpid_num> pb_65H_read_type_0_iot_id_MAX)
       {
         logout("json_readAttr_single_num_by_dpid error: dpid_num(%d) >%d outofrange\n",dpid_num,pb_65H_read_type_0_iot_id_MAX );

         dpid_num = pb_65H_read_type_0_iot_id_MAX;
       }
   

        //-------------------------------------------------------------------------------------
            for(uint8_t z_idx=0; z_idx<dpid_num ;z_idx++)
            {
                cjs_Z[z_idx]  = cJSON_CreateObject();//创建一个对象     

                if (cjs_Z[z_idx] == NULL)
                {
                    logout("cJSON_CreateObject error: cjs_Z[%d]\n",z_idx );              
                    goto lab_exit;
                }


               cJSON_AddNumberToObject(cjs_Z[z_idx],	"dpid",	dpid_buf[z_idx] );

               cJSON_AddItemToArray(cjs_body,	cjs_Z[z_idx] );	//添加对象到数组中
            }
        //-------------------------------------------------------------------------------------
	cJSON_AddItemToObject(cjs_root,	"body",	cjs_body );	//添加数组对象到跟对象




    //JSON数据结构转换为JSON字符串
#if CJSON_PRINT_UNFORM_ENABLE
	cjs_str = cJSON_PrintUnformatted(cjs_root);    //没有空格符的格式=====提高通信效率------
#else
	cjs_str = cJSON_Print(cjs_root);		         // 有空格符的格式------便于人工阅读识别-------------
#endif




    if (cjs_str == NULL)
    {
    	printf("cJSON_Print error!\n");	            
        goto lab_exit;
    }

#if CJSON_PRINT_ENABLE
	printf("%s\n",cjs_str);		//输出字符串
#endif



	//send(cjs_str);      //发送数据
    
    //返回值 0---发送失败，1---发送成功
    gw_ktj_TCP_ClientSend( (uint8_t*)cjs_str, strlen(cjs_str) );

	// free(cjs_str);		//需要手动释放内存空间---
     cJSON_free(cjs_str ); 


lab_exit:

    if ( cjs_root != NULL)
    {
	    cJSON_Delete(cjs_root);		//清除结构体
    }

    cjs_root = NULL;  
    cjs_str = NULL;

}




    //读单个设备的几个属性
void json_readAttr_single_num_by_name(uint8_t dev_addr, uint8_t channel,uint8_t nodeType,uint8_t attrNum,  char* attrStart )
{
    cJSON* cjs_root = NULL;  
    cJSON* cjs_head = NULL;
    cJSON* cjs_data = NULL;

    char*  cjs_str  = NULL;


	//printf("%s,cmd=%s,data=%s\n",__FUNCTION__,cmd_str,data_str);		//输出字符串

	
	cjs_root = cJSON_CreateObject();   //创建一个对象
    if (cjs_root == NULL)
    {
        goto lab_exit;
    }

	cjs_head = cJSON_CreateObject();   //创建一个对象
    if (cjs_head == NULL)
    {
        goto lab_exit;
    }


	cjs_data = cJSON_CreateObject();   //创建一个对象
    if (cjs_data == NULL)
    {
        goto lab_exit;
    }


////---------------head 部分-----------------------------------------------

	set_json_comm_item(cjs_root, TYPE_CMD, "readAttr", gui_js_api_msg_id++ ); 


////{"head":{"gatewayId":"gw_1C32830085B0","msgId":0,"cmd":"readAttr"},"data":{"nodeType":1,"channel":2,"privAddr":1,"dpid":32768,"attrNum":1}}
////---------------data 部分-----------------------------------------------

//	"data": {
//		"mac": "FFFFFFFFFFFF",
//		"nodeType": 1,
//		"channel": 2,
//		"privAddr": 1,
//		"attrStart": "thOlL",      //  属性名
//		"attrNum": 1           // 固定为1   
//	}
//



	cJSON_AddNumberToObject(cjs_data,	"privAddr",	dev_addr);
	cJSON_AddNumberToObject(cjs_data,	"channel",	channel);
	cJSON_AddNumberToObject(cjs_data,	"nodeType",	nodeType);

	cJSON_AddStringToObject(cjs_data,	"attrStart",	attrStart);
	cJSON_AddNumberToObject(cjs_data,	"attrNum",	attrNum);

	//cJSON_AddNumberToObject(cjs_data,	"name",	"rs-485sensor");
    //cJSON_AddNumberToObject(cjs_data,	"deviceName",	"rs-485sensor");
    
	//cJSON_AddNumberToObject(cjs_data,	"mac",	"FFFFFFFFFFFF");

    cJSON_AddItemToObject(cjs_root,	"data",	cjs_data);	//对象



    //JSON数据结构转换为JSON字符串
#if CJSON_PRINT_UNFORM_ENABLE
	cjs_str = cJSON_PrintUnformatted(cjs_root);    //没有空格符的格式=====提高通信效率------
#else
	cjs_str = cJSON_Print(cjs_root);		         // 有空格符的格式------便于人工阅读识别-------------
#endif



    if (cjs_str == NULL)
    {
    	printf("cJSON_Print error!\n");	            
        goto lab_exit;
    }


#if CJSON_PRINT_ENABLE
	printf("%s\n",cjs_str);		//输出字符串
#endif		//输出字符串

	//send(cjs_str);      //发送数据
    
    //返回值 0---发送失败，1---发送成功
    gw_ktj_TCP_ClientSend( (uint8_t*)cjs_str, strlen(cjs_str) );

	// free(cjs_str);		//需要手动释放内存空间---
     cJSON_free(cjs_str ); 


lab_exit:

    if ( cjs_root != NULL)
    {
	    cJSON_Delete(cjs_root);		//清除结构体
    }

    cjs_root = NULL;  
    cjs_str = NULL;

}



// {
// 	"data": {
// 		"deviceName": "oilLevel_2_1",
// 		"mac": "FFFFFFFFFFFF",
// 		"nodeType": 1,
// 		"channel": 1,
// 		"privAddr": 1
// 	},
// 	"attrLst": [{
// 		"name": "thTH",
// 		"lable": "温度过高阈值",    //  可以不要
// 		"val": "98",
// 		"order": 1                //  可以不要
// 	}],
// 	"head": {
// 		"gatewayId": "gw_1C32830600E6",
// 		"msgId": 0,
// 		"timeStamp": 0,
// 		"cmd": "setAttr",
// 		"appuserId": 27                //  可以不要
// 	}
// }




//"nodeType":1,"channel":2,"privAddr":1,
//   info.node_type = 1;
//   info.chan_addr = 1;
//   info.channel = 2;

// 	"attrLst": [{
// 		"name": "thTH",
// 		"lable": "温度过高阈值",    //  可以不要
// 		"val": "98",  //这个事数值 不是字符串
//"deviceName": "oilLevel_2_1",
uint8_t json_write_setAttr_dev( dev_mod_info_t* info,const char* dev_name_str,const char* attr_name_str ,uint32_t attr_val )
{
    cJSON* cjs_root = NULL;  
    cJSON* cjs_data = NULL;
    cJSON* cjs_attr_array = NULL;
    cJSON* cjs_item = NULL;    
    char*  cjs_str  = NULL;


 char attr_val_str[32];


  // char gatewayId_str[]="010000000780";
	
	cjs_root = cJSON_CreateObject();   //创建一个对象
    if (cjs_root == NULL)
    {
        goto lab_exit;
    }


	cjs_data = cJSON_CreateObject();   //创建一个对象data
    if (cjs_data == NULL)
    {
        goto lab_exit;
    }



// 	"head": {
// 		"gatewayId": "gw_1C32830600E6",
// 		"msgId": 0,
// 		"timeStamp": 0,
// 		"cmd": "setAttr",
// 		"appuserId": 27                //  可以不要
// 	}
// }


	if(  0==set_json_comm_item(cjs_root, TYPE_CMD, "setAttr", gui_js_api_msg_id++) )
    {
        goto lab_exit;     
    }



// {
// 	"data": {
// 		"deviceName": "oilLevel_2_1",
// 		"mac": "FFFFFFFFFFFF",
// 		"nodeType": 1,
// 		"channel": 1,
// 		"privAddr": 1
// 	},


    if(NULL !=dev_name_str)
    {
        cJSON_AddStringToObject(cjs_data,	"deviceName",	dev_name_str );
    }
	

   // if(NULL !=node_mac)
    {
        cJSON_AddStringToObject(cjs_data,	"mac",	"FFFFFFFFFFFF" );
    }
	
	
    if(NULL !=info)
    {
        cJSON_AddNumberToObject(cjs_data,	"nodeType",	info->node_type );
        cJSON_AddNumberToObject(cjs_data,	"channel",	info->channel );        
        cJSON_AddNumberToObject(cjs_data,	"privAddr",	info->chan_addr );    
    }
	

	cJSON_AddItemToObject(cjs_root,	"data",	cjs_data );	//对象


// 	"attrLst": [{
// 		"name": "thTH",
// 		"lable": "温度过高阈值",    //  可以不要
// 		"val": "98",
// 		"order": 1                //  可以不要
// 	}],


	cjs_attr_array  = cJSON_CreateArray();				//创建一个数组
    if (cjs_attr_array == NULL)
    {
        goto lab_exit;
    }


	cjs_item = cJSON_CreateObject();   //创建一个对象  attr
    if (cjs_item == NULL)
    {
        goto lab_exit;
    }


    if(NULL !=attr_name_str)
    {
        cJSON_AddStringToObject(cjs_item,	"name",	attr_name_str );
    }
	
    if(NULL !=attr_name_str)
    {      
          memset(attr_val_str,0,sizeof(attr_val_str) );
          sprintf(attr_val_str,"%d",  attr_val);
          printf("attr_val=%d,attr_val_str=%s",  attr_val,attr_val_str);

        //NumToStr(  attr_val, attr_val_str ) ;
        cJSON_AddStringToObject(cjs_item,	"val",	attr_val_str  ); 
        //cJSON_AddNumberToObject(cjs_item,	"val",	attr_val  );  
    }
	

    cJSON_AddItemToArray(cjs_attr_array,	cjs_item );

	cJSON_AddItemToObject(cjs_root,	"attrLst",	cjs_attr_array );	//对象



    //JSON数据结构转换为JSON字符串
#if CJSON_PRINT_UNFORM_ENABLE
	cjs_str = cJSON_PrintUnformatted(cjs_root);    //没有空格符的格式=====提高通信效率------
#else
	cjs_str = cJSON_Print(cjs_root);		         // 有空格符的格式------便于人工阅读识别-------------
#endif


    if (cjs_str == NULL)
    {
      	printf("cJSON_Print error!\n");	          
        goto lab_exit;
    }


#if CJSON_PRINT_ENABLE
	printf("%s\n",cjs_str);		//输出字符串
#endif		//输出字符串

	//send(cjs_str);      //发送数据

    //返回值 0---发送失败，1---发送成功
    gw_ktj_TCP_ClientSend( (uint8_t*)cjs_str, strlen(cjs_str) );


   // free(cjs_str );   //释放内存空间---尚未确定是否需要这步---????--
    cJSON_free(cjs_str ); 

lab_exit:

    if ( cjs_root != NULL)
    {
	    cJSON_Delete(cjs_root);		//清除结构体
    }

    cjs_root = NULL;  
    cjs_str = NULL;

 return 1;

}





/////  // 一次写设备所有R/W的配置参数----json 协议参数用的是name---需要维护name 表---
uint8_t json_write_setAttr_dev_config_all_with_name(const uint8_t index,const uint8_t seq, dev_mod_info_t* info )
{
    cJSON* cjs_root = NULL;  
    cJSON* cjs_data = NULL;
    cJSON* cjs_attr_array = NULL;
 //   cJSON* cjs_item = NULL;    
    char*  cjs_str  = NULL;

    uint8_t z_idx;

#define   ATTR_VAL_STR_BUF_MAX       (32u)
 //char attr_val_str[8][ATTR_VAL_STR_BUF_MAX];

 char attr_val_str_buf[ATTR_VAL_STR_BUF_MAX];
 char name_str_buf[ATTR_VAL_STR_BUF_MAX];


#define  key_name_MAX(a,b)  ( ((a)>(b))?(a):(b) )

  cJSON *cjs_Z[ key_name_MAX(battery_iot_id_key_name_table_mult_write_end,generator_iot_id_key_name_table_mult_write_end ) ] ;	
  // cJSON *cjs_Z[battery_iot_id_key_name_table_mult_write_end] ;	
  // cJSON *cjs_Z[generator_iot_id_key_name_table_mult_write_end] ;	
  //cJSON *cjs_Z[64] ;	





  LOG_NAME();

  // char gatewayId_str[]="010000000780";
	
	cjs_root = cJSON_CreateObject();   //创建一个对象
    if (cjs_root == NULL)
    {
        goto lab_exit;
    }


	cjs_data = cJSON_CreateObject();   //创建一个对象data
    if (cjs_data == NULL)
    {
        goto lab_exit;
    }



// 	"head": {
// 		"gatewayId": "gw_1C32830600E6",
// 		"msgId": 0,
// 		"timeStamp": 0,
// 		"cmd": "setAttr",
// 		"appuserId": 27                //  可以不要
// 	}
// }


	if(  0==set_json_comm_item(cjs_root, TYPE_CMD, "setAttr", seq ) )   //gui_js_api_msg_id++
    {
        goto lab_exit;     
    }



// {
// 	"data": {
// 		"deviceName": "oilLevel_2_1",
// 		"mac": "FFFFFFFFFFFF",
// 		"nodeType": 1,
// 		"channel": 1,
// 		"privAddr": 1
// 	},


    if(NULL !=info->pdev_name_str)
    {
        memset(name_str_buf,0, sizeof(name_str_buf) );
        strncpy(name_str_buf, info->pdev_name_str, sizeof(name_str_buf) );
        logout("name_str_buf=%s", name_str_buf);
        cJSON_AddStringToObject(cjs_data,	"deviceName",	name_str_buf );//dev_name=eleMeter_1_5
       // cJSON_AddStringToObject(cjs_data,	"deviceName",	"eleMeter_1_5" );
    }
	

   // if(NULL !=node_mac)
    {
        cJSON_AddStringToObject(cjs_data,	"mac",	"FFFFFFFFFFFF" );
    }
	
	
    if(NULL !=info)
    {
        cJSON_AddNumberToObject(cjs_data,	"nodeType",	1);//info->node_type-----固定为1
        cJSON_AddNumberToObject(cjs_data,	"channel",	info->channel );        
        cJSON_AddNumberToObject(cjs_data,	"privAddr",	info->chan_addr );    
    }
	

	cJSON_AddItemToObject(cjs_root,	"data",	cjs_data );	//对象


// 	"attrLst": [{
// 		"name": "thTH",
// 		"lable": "温度过高阈值",    //  可以不要
// 		"val": "98",
// 		"order": 1                //  可以不要
// 	}],



	cjs_attr_array  = cJSON_CreateArray();				//创建一个数组
    if (cjs_attr_array == NULL)
    {
        goto lab_exit;
    }

// gw_ktj socket send done
// 20:29:35- ETH_1 local_ktj_js Rx: len=1624
// {"head":{"gatewayId":"gw_1C3283005078","replaceId":"","msgId":55,"timeStamp":1732537775,"response":"readAttr"},
// "data":{"nodeType":1,"channel":2,"privAddr":1,"mac":"FFFFFFFFFFFF","name":"oilLevel_2_1","pid":"4001","totalFrame":1,"currFrame":1,"totalAttr":23,"itemCnt":23},
// "attrLst":[{"name":"olH","lable":"液位高","val":610},{"name":"olL","lable":"液位低","val":25087},{"name":"tempe","lable":"温度1","val":367},
// {"name":"mbAddr","lable":"地址","val":0},

// {"name":"alarmEn","lable":"液位报警使能","val":15},
// {"name":"thOlL","lable":"液位过低阈值","val":11100},
// // {"name":"thOlH","lable":"液位过高阈值","val":11100},
// {"name":"thTL","lable":"温度过低阈值","val":33},
// {"name":"thTH","lable":"温度过高阈值","val":123},

   switch ( info->node_type ) 
   {
        case IOT_SENSOR_liquid:
        {

            liquid_attr_t*  pattr_obj=NULL;  
            pattr_obj = liquid_get_obj( index) ; 

    ///----------------------start-----// {"name":"alarmEn","lable":"液位报警使能","val":15},-----------------------------------------------------
 
            cJSON *cjs_Z0  = cJSON_CreateObject();				//创建一个对象     
            cJSON_AddStringToObject(cjs_Z0,	"name",	"alarmEn" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );

            sprintf(attr_val_str_buf,"%d",  pattr_obj->config.alarm_enable.value);
            printf("attr_val=%d,attr_val_str=%s\n",  pattr_obj->config.alarm_enable.value,attr_val_str_buf);

            //NumToStr(  attr_val, attr_val_str ) ;
            cJSON_AddStringToObject(cjs_Z0,	"val",	attr_val_str_buf  ); 
            //cJSON_AddNumberToObject(cjs_item,	"val",	attr_val  );  

            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z0 );


    ///----------------------start----// {"name":"thOlL","lable":"液位过低阈值","val":11100},------------------------------------------------------

            cJSON *cjs_Z1  = cJSON_CreateObject();				//创建一个对象   
            cJSON_AddStringToObject(cjs_Z1,	"name",	"thOlL" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );

            sprintf(attr_val_str_buf,"%d",  pattr_obj->config.under_level_th);
            printf("attr_val=%d,attr_val_str=%s\n", pattr_obj->config.under_level_th ,attr_val_str_buf);
            cJSON_AddStringToObject(cjs_Z1,	"val",	attr_val_str_buf  ); 

            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z1 );



    ///----------------------start----// {"name":"thOlH","lable":"液位过高阈值","val":11100},-----------------------------------------------------

            cJSON *cjs_Z2  = cJSON_CreateObject();				//创建一个对象   
            cJSON_AddStringToObject(cjs_Z2,	"name",	"thOlH" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );

            sprintf(attr_val_str_buf,"%d",  pattr_obj->config.over_level_th);
            printf("attr_val=%d,attr_val_str=%s\n",  pattr_obj->config.over_level_th ,attr_val_str_buf);
            cJSON_AddStringToObject(cjs_Z2,	"val",	attr_val_str_buf  ); 

            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z2 );

    ///----------------------start-// {"name":"thTL","lable":"温度过低阈值","val":33},-----------------------------------------------------

            cJSON *cjs_Z3  = cJSON_CreateObject();				//创建一个对象            
            cJSON_AddStringToObject(cjs_Z3,	"name",	"thTL" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );

            sprintf(attr_val_str_buf,"%d",  pattr_obj->config.under_temper_th);
            printf("attr_val=%d,attr_val_str=%s\n",  pattr_obj->config.under_temper_th ,attr_val_str_buf);
            cJSON_AddStringToObject(cjs_Z3,	"val",	attr_val_str_buf  ); 

            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z3 );

    ///----------------------start---// {"name":"thTH","lable":"温度过高阈值","val":123},-----------------------------------------------------

            cJSON *cjs_Z4  = cJSON_CreateObject();				//创建一个对象            
            cJSON_AddStringToObject(cjs_Z4,	"name",	"thTH" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );

            sprintf(attr_val_str_buf,"%d",  pattr_obj->config.over_temper_th);
            printf("attr_val=%d,attr_val_str=%s\n",  pattr_obj->config.over_temper_th ,attr_val_str_buf);
            cJSON_AddStringToObject(cjs_Z4,	"val",	attr_val_str_buf  ); 

            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z4 );


    ///----------------------start------------------------------------------------------

    cJSON *cjs_Z5  = cJSON_CreateObject();				//创建一个对象            
    cJSON_AddStringToObject(cjs_Z5,	"name",	"oilChkInterval" );

    memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );

    sprintf(attr_val_str_buf,"%d",  pattr_obj->config.monitor_sec_th);
    printf("attr_val=%d,attr_val_str=%s\n",  pattr_obj->config.monitor_sec_th ,attr_val_str_buf);
    cJSON_AddStringToObject(cjs_Z5,	"val",	attr_val_str_buf  ); 

    cJSON_AddItemToArray(cjs_attr_array,	cjs_Z5 );

    ///----------------------start-------------------------------------------------------

    cJSON *cjs_Z6  = cJSON_CreateObject();				//创建一个对象            
    cJSON_AddStringToObject(cjs_Z6,	"name",	"thOilConsume" );

    memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );

    sprintf(attr_val_str_buf,"%d",  pattr_obj->config.monitor_level_th);
    printf("attr_val=%d,attr_val_str=%s\n",  pattr_obj->config.monitor_level_th ,attr_val_str_buf);
    cJSON_AddStringToObject(cjs_Z6,	"val",	attr_val_str_buf  ); 

    cJSON_AddItemToArray(cjs_attr_array,	cjs_Z6 );

        }break;

       case IOT_SENSOR_temper_humidity:
       {
            temp_humi_attr_t*  pattr_obj=NULL;  
            pattr_obj = temp_humi_get_obj( index) ; 

///----------------------------------------------------------------------
 
// 0x0610	alarmEn	温湿度报警使能
// 0x0611	thHL	湿度过低阈值
// 0x0612	thHH	湿度过高阈值
// 0x0613	tempeChkInterval	温度变化监测周期
// 0x0614	thTempeRise	温度变化异常值
// 0x0615	humChkInterval	湿度变化监测周期
// 0x0616	thHumChange	湿度变化异常值
// thTL	温度过低阈值
// thTH	温度过高阈值



            cJSON *cjs_Z0  = cJSON_CreateObject();				//创建一个对象     
            cJSON_AddStringToObject(cjs_Z0,	"name",	"alarmEn" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );

            sprintf(attr_val_str_buf,"%d",  pattr_obj->config.alarm_enable.value);
            printf("attr_val=%d,attr_val_str=%s\n",  pattr_obj->config.alarm_enable.value,attr_val_str_buf);

            //NumToStr(  attr_val, attr_val_str ) ;
            cJSON_AddStringToObject(cjs_Z0,	"val",	attr_val_str_buf  ); 
            //cJSON_AddNumberToObject(cjs_item,	"val",	attr_val  );  

            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z0 );


    ///----------------------------------------------------------------------------

            cJSON *cjs_Z1  = cJSON_CreateObject();				//创建一个对象   
            cJSON_AddStringToObject(cjs_Z1,	"name",	"thHL" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );

            sprintf(attr_val_str_buf,"%d",  pattr_obj->config.under_humidity_th);
            printf("attr_val=%d,attr_val_str=%s\n", pattr_obj->config.under_humidity_th ,attr_val_str_buf);
            cJSON_AddStringToObject(cjs_Z1,	"val",	attr_val_str_buf  ); 

            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z1 );



    ///----------------------------------------------------------------------

            cJSON *cjs_Z2  = cJSON_CreateObject();				//创建一个对象   
            cJSON_AddStringToObject(cjs_Z2,	"name",	"thHH" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );

            sprintf(attr_val_str_buf,"%d",  pattr_obj->config.over_humidity_th);
            printf("attr_val=%d,attr_val_str=%s\n",  pattr_obj->config.over_humidity_th ,attr_val_str_buf);
            cJSON_AddStringToObject(cjs_Z2,	"val",	attr_val_str_buf  ); 

            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z2 );

    ///------------------------------------------------------------------------

            cJSON *cjs_Z3  = cJSON_CreateObject();				//创建一个对象            
            cJSON_AddStringToObject(cjs_Z3,	"name",	"thTL" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );

            sprintf(attr_val_str_buf,"%d",  pattr_obj->config.under_temper_th);
            printf("attr_val=%d,attr_val_str=%s\n",  pattr_obj->config.under_temper_th ,attr_val_str_buf);
            cJSON_AddStringToObject(cjs_Z3,	"val",	attr_val_str_buf  ); 

            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z3 );

    ///---------------------------------------------------------------------------

            cJSON *cjs_Z4  = cJSON_CreateObject();				//创建一个对象            
            cJSON_AddStringToObject(cjs_Z4,	"name",	"thTH" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );

            sprintf(attr_val_str_buf,"%d",  pattr_obj->config.over_temper_th);
            printf("attr_val=%d,attr_val_str=%s\n",  pattr_obj->config.over_temper_th ,attr_val_str_buf);
            cJSON_AddStringToObject(cjs_Z4,	"val",	attr_val_str_buf  ); 

            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z4 );


 #if 0           

            ///---------------------------------------------------------------------------

            cJSON *cjs_Z5  = cJSON_CreateObject();				//创建一个对象            
            cJSON_AddStringToObject(cjs_Z5,	"name",	"tempeChkInterval" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );

            sprintf(attr_val_str_buf,"%d",  pattr_obj->config.temper_monitor_sec_th);
            printf("attr_val=%d,attr_val_str=%s\n",  pattr_obj->config.temper_monitor_sec_th ,attr_val_str_buf);
            cJSON_AddStringToObject(cjs_Z5,	"val",	attr_val_str_buf  ); 

            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z5 );


            ///----------//  0x0614	thTempeRise	温度变化异常值-----------------------------------------------------------------

            cJSON *cjs_Z6  = cJSON_CreateObject();	         
            cJSON_AddStringToObject(cjs_Z6,	"name",	"thTempeRise" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );

            sprintf(attr_val_str_buf,"%d",  pattr_obj->config.temper_monitor_th);
            printf("attr_val=%d,attr_val_str=%s\n",  pattr_obj->config.temper_monitor_th ,attr_val_str_buf);
            cJSON_AddStringToObject(cjs_Z6,	"val",	attr_val_str_buf  ); 

            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z6 );


            ///-------------// 0x0615	humChkInterval	湿度变化监测周期--------------------------------------------------------------

            cJSON *cjs_Z7  = cJSON_CreateObject();				//创建一个对象            
            cJSON_AddStringToObject(cjs_Z7,	"name",	"humChkInterval" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );

            sprintf(attr_val_str_buf,"%d",  pattr_obj->config.humidity_monitor_sec_th);
            printf("attr_val=%d,attr_val_str=%s\n",  pattr_obj->config.humidity_monitor_sec_th ,attr_val_str_buf);
            cJSON_AddStringToObject(cjs_Z7,	"val",	attr_val_str_buf  ); 

            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z7 );


            ///--------// 0x0616	thHumChange	湿度变化异常值-------------------------------------------------------------------

            cJSON *cjs_Z8  = cJSON_CreateObject();				//创建一个对象            
            cJSON_AddStringToObject(cjs_Z8,	"name",	"thHumChange" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );

            sprintf(attr_val_str_buf,"%d",  pattr_obj->config.humidity_monitor_th);
            printf("attr_val=%d,attr_val_str=%s\n",  pattr_obj->config.humidity_monitor_th ,attr_val_str_buf);
            cJSON_AddStringToObject(cjs_Z8,	"val",	attr_val_str_buf  ); 

            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z8 );



#endif


        }break;


        case IOT_SENSOR_dido: //door 门禁传感器
        {
 
            dev_dido_attr_t*  pattr_obj=NULL;  
            pattr_obj = dev_dido_get_obj( index) ; 


    ///---------------------------------------------------------------------
    ////{"name":"do","lable":"do","class":17,"dpid":1058,"val":0,"type":0},
    // {"data":{"deviceName":"eleMeter_1_5","mac":"FFFFFFFFFFFF","nodeType":1,"channel":1,"privAddr":5},
    // "attrLst":[{"class":17,"dpid":32857,"lable":"do2","name":"do2","type":0,"val":"0","order":1}],
    // "head":{"gatewayId":"gw_CC0500CFB180","msgId":0,"timeStamp":0,"cmd":"setAttr","appuserId":27,"replaceId":"gw_1738909887431",
    
    
    // Tcp_Tx_ch=1, local_ktj_js
    // {"head":{"gatewayId":"gw_CC0500CFB180","msgId":44,"timeStamp":0,"cmd":"setAttr"},
    // "data":{"deviceName":"eleMeter_1_5","mac":"FFFFFFFFFFFF","nodeType":1,"channel":1,"privAddr":5},
    // "attrLst":[{"name":"do1","val":"1"},{"name":"do2","val":"1"}]}
    


            cJSON *cjs_Z0  = cJSON_CreateObject();				//创建一个对象     
            cJSON_AddStringToObject(cjs_Z0,	"name",	"do1" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );
//            sprintf(attr_val_str_buf,"%d",  (pattr_obj->data.output.value&0x00000001));
            sprintf(attr_val_str_buf,"%d",  (pattr_obj->config.do1));

            cJSON_AddStringToObject(cjs_Z0,	"val",	attr_val_str_buf ); 
            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z0 );


            cJSON *cjs_Z01  = cJSON_CreateObject();				//创建一个对象     
            cJSON_AddStringToObject(cjs_Z01,	"name",	"do2" );
            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );

    //        sprintf(attr_val_str_buf,"%d",  ((pattr_obj->data.output.value>>1)&0x00000001));
            sprintf(attr_val_str_buf,"%d",  (pattr_obj->config.do2));

            cJSON_AddStringToObject(cjs_Z01,	"val",	attr_val_str_buf ); 
            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z01 );



            cJSON *cjs_Z02  = cJSON_CreateObject();				//创建一个对象     
            cJSON_AddStringToObject(cjs_Z02,	"name",	"do3" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );
         //  sprintf(attr_val_str_buf,"%d",  ((pattr_obj->data.output.value>>2)&0x00000001));
            sprintf(attr_val_str_buf,"%d",  (pattr_obj->config.do3));

            cJSON_AddStringToObject(cjs_Z02,	"val",	attr_val_str_buf ); 
            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z02 );


            cJSON *cjs_Z03  = cJSON_CreateObject();				//创建一个对象     
            cJSON_AddStringToObject(cjs_Z03,	"name",	"do4" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );
//          sprintf(attr_val_str_buf,"%d",  ((pattr_obj->data.output.value>>3)&0x00000001));
            sprintf(attr_val_str_buf,"%d",  (pattr_obj->config.do4));

            cJSON_AddStringToObject(cjs_Z03,	"val",	attr_val_str_buf ); 
            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z03 );

           ////..................................



           cJSON *cjs_Z04  = cJSON_CreateObject();			 
           cJSON_AddStringToObject(cjs_Z04,	"name",	"almEn" );

           memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );
           sprintf(attr_val_str_buf,"%d",  (pattr_obj->config.almEn.value));

           cJSON_AddStringToObject(cjs_Z04,	"val",	attr_val_str_buf ); 
           cJSON_AddItemToArray(cjs_attr_array,	cjs_Z04 );

          ////..................................

          cJSON *cjs_Z05  = cJSON_CreateObject();			 
          cJSON_AddStringToObject(cjs_Z05,	"name",	"almCond" );

          memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );
          sprintf(attr_val_str_buf,"%d",  (pattr_obj->config.almCond.value));

          cJSON_AddStringToObject(cjs_Z05,	"val",	attr_val_str_buf ); 
          cJSON_AddItemToArray(cjs_attr_array,	cjs_Z05 );

#if dev_dido_ver0_enable

#endif


        } break;



        case IOT_SENSOR_ac_meter:  
        {

            ac_meter_attr_t*  pattr_obj=NULL;  
            pattr_obj = ac_meter_get_obj( index) ; 


    ///---------------------------------------------------------------------
    ////{"name":"do","lable":"do","class":17,"dpid":1058,"val":0,"type":0},
    // {"data":{"deviceName":"eleMeter_1_5","mac":"FFFFFFFFFFFF","nodeType":1,"channel":1,"privAddr":5},
    // "attrLst":[{"class":17,"dpid":32857,"lable":"do2","name":"do2","type":0,"val":"0","order":1}],
    // "head":{"gatewayId":"gw_CC0500CFB180","msgId":0,"timeStamp":0,"cmd":"setAttr","appuserId":27,"replaceId":"gw_1738909887431",
    
    
    // Tcp_Tx_ch=1, local_ktj_js
    // {"head":{"gatewayId":"gw_CC0500CFB180","msgId":44,"timeStamp":0,"cmd":"setAttr"},
    // "data":{"deviceName":"eleMeter_1_5","mac":"FFFFFFFFFFFF","nodeType":1,"channel":1,"privAddr":5},
    // "attrLst":[{"name":"do1","val":"1"},{"name":"do2","val":"1"}]}
    

#if 0    //  配置参数的时候---不包括do,do需要单独控制
            cJSON *cjs_Z0  = cJSON_CreateObject();				//创建一个对象     
            cJSON_AddStringToObject(cjs_Z0,	"name",	"do1" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );
            //sprintf(attr_val_str_buf,"%d",  (pattr_obj->data.DO&0x00000001));
            sprintf(attr_val_str_buf,"%d",  (pattr_obj->config.do1));

            cJSON_AddStringToObject(cjs_Z0,	"val",	attr_val_str_buf ); 
            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z0 );


            cJSON *cjs_Z01  = cJSON_CreateObject();		
            cJSON_AddStringToObject(cjs_Z01,	"name",	"do2" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );
  //          sprintf(attr_val_str_buf,"%d",  ((pattr_obj->data.DO>>1)&0x00000001));
            sprintf(attr_val_str_buf,"%d",  (pattr_obj->config.do2));   

            cJSON_AddStringToObject(cjs_Z01,	"val",	attr_val_str_buf ); 
            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z01 );

#endif



#if 0    //   交流电表物模型-v1.4---没有此两项-----

            cJSON *cjs_Z02  = cJSON_CreateObject();		
            cJSON_AddStringToObject(cjs_Z02,	"name",	"do3" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );
            sprintf(attr_val_str_buf,"%d",  ((pattr_obj->data.DO>>2)&0x00000001));
            cJSON_AddStringToObject(cjs_Z02,	"val",	attr_val_str_buf ); 
            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z02 );

            cJSON *cjs_Z03  = cJSON_CreateObject();		
            cJSON_AddStringToObject(cjs_Z03,	"name",	"do4" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );
            sprintf(attr_val_str_buf,"%d",  ((pattr_obj->data.DO>>3)&0x00000001));
            cJSON_AddStringToObject(cjs_Z03,	"val",	attr_val_str_buf ); 
            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z03 );

#endif


        ///---------------------配置参数------------------------------------------------------

        ///---------------------pulseConst参数----------------------------------------------------
        cJSON *cjs_Z1  = cJSON_CreateObject();				//创建一个对象   
        cJSON_AddStringToObject(cjs_Z1,	"name",	"pulseConst" );
        cJSON_AddNumberToObject(cjs_Z1,	"val", pattr_obj->config.pulseConst  ); 
        cJSON_AddItemToArray(cjs_attr_array,	cjs_Z1 );


//-----------------物模型更新到 <<交流电表物模型-v1.4>>---------------------------------------

        cJSON *cjs_Z2  = cJSON_CreateObject();				//创建一个对象   
        cJSON_AddStringToObject(cjs_Z2,	"name",	"almEn" );
        cJSON_AddNumberToObject(cjs_Z2,	"val",	pattr_obj->config.almEn.value  ); 
        cJSON_AddItemToArray(cjs_attr_array,	cjs_Z2 );


    //  ///-------交流电表物模型-v1.4--------------
        cJSON *cjs_Z3  = cJSON_CreateObject();				//创建一个对象   
        cJSON_AddStringToObject(cjs_Z3,	"name",	"thVoltHi" );
        cJSON_AddNumberToObject(cjs_Z3,	"val",	pattr_obj->config.thVoltHi ); 
        cJSON_AddItemToArray(cjs_attr_array,	cjs_Z3 );

        cJSON *cjs_Z4  = cJSON_CreateObject();				//创建一个对象   
        cJSON_AddStringToObject(cjs_Z4,	"name",	"thVoltLow" );
        cJSON_AddNumberToObject(cjs_Z4,	"val",	pattr_obj->config.thVoltLow ); 
        cJSON_AddItemToArray(cjs_attr_array,	cjs_Z4 );

        cJSON *cjs_Z5  = cJSON_CreateObject();				//创建一个对象   
        cJSON_AddStringToObject(cjs_Z5,	"name",	"thFreqHi" );
        cJSON_AddNumberToObject(cjs_Z5,	"val",	pattr_obj->config.thFreqHi ); 
        cJSON_AddItemToArray(cjs_attr_array,	cjs_Z5 );


        cJSON *cjs_Z6  = cJSON_CreateObject();				//创建一个对象   
        cJSON_AddStringToObject(cjs_Z6,	"name",	"thFreqLow" );
        cJSON_AddNumberToObject(cjs_Z6,	"val",	pattr_obj->config.thFreqLow ); 
        cJSON_AddItemToArray(cjs_attr_array,	cjs_Z6 );


        cJSON *cjs_Z7  = cJSON_CreateObject();				//创建一个对象   
        cJSON_AddStringToObject(cjs_Z7,	"name",	"thPowerHi" );
        cJSON_AddNumberToObject(cjs_Z7,	"val",	pattr_obj->config.thPowerHi ); 
        cJSON_AddItemToArray(cjs_attr_array,	cjs_Z7 );

        cJSON *cjs_Z8  = cJSON_CreateObject();				//创建一个对象   
        cJSON_AddStringToObject(cjs_Z8,	"name",	"thPowerLow" );
        cJSON_AddNumberToObject(cjs_Z8,	"val",	pattr_obj->config.thPowerLow ); 
        cJSON_AddItemToArray(cjs_attr_array,	cjs_Z8 );


        cJSON *cjs_Z9  = cJSON_CreateObject();				//创建一个对象   
        cJSON_AddStringToObject(cjs_Z9,	"name",	"thCurrHi" );
        cJSON_AddNumberToObject(cjs_Z9,	"val",	pattr_obj->config.thCurrHi ); 
        cJSON_AddItemToArray(cjs_attr_array,	cjs_Z9 );

        cJSON *cjs_Z10  = cJSON_CreateObject();				//创建一个对象   
        cJSON_AddStringToObject(cjs_Z10,	"name",	"thCurrLow" );
        cJSON_AddNumberToObject(cjs_Z10,	"val",	pattr_obj->config.thCurrLow ); 
        cJSON_AddItemToArray(cjs_attr_array,	cjs_Z10 );


#if 1    //---------------------------交流电表json协议可读写---------

    ///---------------------配置参数------------------------------------------------------

            cJSON *cjs_Z11  = cJSON_CreateObject();				//创建一个对象   
            cJSON_AddStringToObject(cjs_Z11,	"name",	"PT" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );

            if(0==pattr_obj->config.PT)
            {//不能为0 
               pattr_obj->config.PT = 1;
            }


            sprintf(attr_val_str_buf,"%d",  pattr_obj->config.PT);
            printf("attr_val=%d,attr_val_str=%s\n", pattr_obj->config.PT ,attr_val_str_buf);
            cJSON_AddStringToObject(cjs_Z11,	"val",	attr_val_str_buf  ); 

            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z11 );



    ///-----------------------------------------------------------------------

            cJSON *cjs_Z12  = cJSON_CreateObject();				//创建一个对象   
            cJSON_AddStringToObject(cjs_Z12,	"name",	"CT" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );

            if(0==pattr_obj->config.CT)
            {//不能为0 
               pattr_obj->config.CT = 1;
            }

            sprintf(attr_val_str_buf,"%d",  pattr_obj->config.CT);
            printf("attr_val=%d,attr_val_str=%s\n",  pattr_obj->config.CT ,attr_val_str_buf);
            cJSON_AddStringToObject(cjs_Z12,	"val",	attr_val_str_buf  ); 

            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z12 );

    ///---------------------------------------------------------------------

#endif



  #if 0 //   ?????-----避免误操作，导致电能清0，需要独立的电能清0指令
    ///---------------------电能清0------------------------------------------------

            cJSON *cjs_Z3  = cJSON_CreateObject();				//创建一个对象            
            cJSON_AddStringToObject(cjs_Z3,	"name",	"rptActEngiT" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );

            sprintf(attr_val_str_buf,"%d",  pattr_obj->data.EnergyP_T);
            printf("attr_val=%d,attr_val_str=%s\n",  pattr_obj->data.EnergyP_T ,attr_val_str_buf);
            cJSON_AddStringToObject(cjs_Z3,	"val",	attr_val_str_buf  ); 

            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z3 );


    ///---------------------------------------------------------------------

            cJSON *cjs_Z4  = cJSON_CreateObject();				//创建一个对象            
            cJSON_AddStringToObject(cjs_Z4,	"name",	"rptActEngiA" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );

            sprintf(attr_val_str_buf,"%d",  pattr_obj->data.EnergyP_A);
            printf("attr_val=%d,attr_val_str=%s\n",  pattr_obj->data.EnergyP_A ,attr_val_str_buf);
            cJSON_AddStringToObject(cjs_Z4,	"val",	attr_val_str_buf  ); 

            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z4 );

            cJSON *cjs_Z5  = cJSON_CreateObject();				//创建一个对象            
            cJSON_AddStringToObject(cjs_Z5,	"name",	"rptActEngiB" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );

            sprintf(attr_val_str_buf,"%d",  pattr_obj->data.EnergyP_B);
            printf("attr_val=%d,attr_val_str=%s\n",  pattr_obj->data.EnergyP_B ,attr_val_str_buf);
            cJSON_AddStringToObject(cjs_Z5,	"val",	attr_val_str_buf  ); 

            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z5 );

            cJSON *cjs_Z6  = cJSON_CreateObject();				//创建一个对象            
            cJSON_AddStringToObject(cjs_Z6,	"name",	"rptActEngiC" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );

            sprintf(attr_val_str_buf,"%d",  pattr_obj->data.EnergyP_C);
            printf("attr_val=%d,attr_val_str=%s\n",  pattr_obj->data.EnergyP_C ,attr_val_str_buf);
            cJSON_AddStringToObject(cjs_Z6,	"val",	attr_val_str_buf  ); 

            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z6 );

#endif


        }break;



        case IOT_SENSOR_dc_meter:  
        {

            dc_meter_attr_t*  pattr_obj=NULL;  
            pattr_obj = dc_meter_get_obj( index) ; 


    ///---------------------------------------------------------------------
    ////{"name":"do","lable":"do","class":17,"dpid":1058,"val":0,"type":0},
    // {"data":{"deviceName":"eleMeter_1_5","mac":"FFFFFFFFFFFF","nodeType":1,"channel":1,"privAddr":5},
    // "attrLst":[{"class":17,"dpid":32857,"lable":"do2","name":"do2","type":0,"val":"0","order":1}],
    // "head":{"gatewayId":"gw_CC0500CFB180","msgId":0,"timeStamp":0,"cmd":"setAttr","appuserId":27,"replaceId":"gw_1738909887431",
    
    
    // Tcp_Tx_ch=1, local_ktj_js
    // {"head":{"gatewayId":"gw_CC0500CFB180","msgId":44,"timeStamp":0,"cmd":"setAttr"},
    // "data":{"deviceName":"eleMeter_1_5","mac":"FFFFFFFFFFFF","nodeType":1,"channel":1,"privAddr":5},
    // "attrLst":[{"name":"do1","val":"1"},{"name":"do2","val":"1"}]}
    


            cJSON *cjs_Z0  = cJSON_CreateObject();				//创建一个对象     
            cJSON_AddStringToObject(cjs_Z0,	"name",	"do1" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );
 //           sprintf(attr_val_str_buf,"%d",  (pattr_obj->data.DO&0x00000001));
            sprintf(attr_val_str_buf,"%d",  (pattr_obj->config.do1));

            cJSON_AddStringToObject(cjs_Z0,	"val",	attr_val_str_buf ); 
            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z0 );


            cJSON *cjs_Z01  = cJSON_CreateObject();				//创建一个对象     
            cJSON_AddStringToObject(cjs_Z01,	"name",	"do2" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );
     //       sprintf(attr_val_str_buf,"%d",  ((pattr_obj->data.DO>>1)&0x00000001));
            sprintf(attr_val_str_buf,"%d",  (pattr_obj->config.do2));

            cJSON_AddStringToObject(cjs_Z01,	"val",	attr_val_str_buf ); 


            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z01 );



#if 1  ///暂时屏蔽不用---车工直流电表json协议只读--写报错------实际电表是可读写-----json协议PT,CT需要大写
    ///---------------------配置参数------------------------------------------------------

            cJSON *cjs_Z1  = cJSON_CreateObject();				//创建一个对象   
            cJSON_AddStringToObject(cjs_Z1,	"name",	"PT" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );

            if(0==pattr_obj->config.PT)
            {//不能为0 
               pattr_obj->config.PT = 1;
            }

            sprintf(attr_val_str_buf,"%d",  pattr_obj->config.PT);
            printf("attr_val=%d,attr_val_str=%s\n", pattr_obj->config.PT ,attr_val_str_buf);
            cJSON_AddStringToObject(cjs_Z1,	"val",	attr_val_str_buf  ); 

            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z1 );



    ///-----------------------------------------------------------------------

            cJSON *cjs_Z2  = cJSON_CreateObject();				//创建一个对象   
            cJSON_AddStringToObject(cjs_Z2,	"name",	"CT" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );


            if(0==pattr_obj->config.CT)
            {//不能为0 
               pattr_obj->config.CT = 1;
            }


            sprintf(attr_val_str_buf,"%d",  pattr_obj->config.CT);
            printf("attr_val=%d,attr_val_str=%s\n",  pattr_obj->config.CT ,attr_val_str_buf);
            cJSON_AddStringToObject(cjs_Z2,	"val",	attr_val_str_buf  ); 

            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z2 );

    ///---------------------------------------------------------------------

#endif

//-----------------物模型更新到 <<直流电表物模型-v1.4>>---------------------------------------

    // uint16_t  thVoltHi	  ;//电压高阈值	R/W	否	配置信息	uint16_t	0x0470	1136
    // uint16_t  thVoltLow	  ;//电压低阈值	R/W	否	配置信息	uint16_t	0x0471	1137
    // uint16_t  thPowerHi	  ;//过功率阈值	R/W	否	配置信息	uint16_t	0x0474	1140
    // uint16_t  thPowerLow  ;//	欠功率阈值	R/W	否	配置信息	uint16_t	0x0475	1141
    // uint16_t  thCurrHi	  ;//过电流阈值	R/W	否	配置信息	uint16_t	0x0476	1142
    // uint16_t  thCurrLow	  ;//欠电流阈值	R/W	否	配置信息	uint16_t	0x047a	1146



        cJSON *cjs_Z02  = cJSON_CreateObject();				//创建一个对象   
        cJSON_AddStringToObject(cjs_Z02,	"name",	"almEn" );
        cJSON_AddNumberToObject(cjs_Z02,	"val",	pattr_obj->config.almEn.value  ); 
        cJSON_AddItemToArray(cjs_attr_array,	cjs_Z02 );


    //  ///-------交流电表物模型-v1.4--------------
        cJSON *cjs_Z3  = cJSON_CreateObject();				//创建一个对象   
        cJSON_AddStringToObject(cjs_Z3,	"name",	"thVoltHi" );
        cJSON_AddNumberToObject(cjs_Z3,	"val",	pattr_obj->config.thVoltHi ); 
        cJSON_AddItemToArray(cjs_attr_array,	cjs_Z3 );

        cJSON *cjs_Z4  = cJSON_CreateObject();				//创建一个对象   
        cJSON_AddStringToObject(cjs_Z4,	"name",	"thVoltLow" );
        cJSON_AddNumberToObject(cjs_Z4,	"val",	pattr_obj->config.thVoltLow ); 
        cJSON_AddItemToArray(cjs_attr_array,	cjs_Z4 );


        cJSON *cjs_Z7  = cJSON_CreateObject();				//创建一个对象   
        cJSON_AddStringToObject(cjs_Z7,	"name",	"thPowerHi" );
        cJSON_AddNumberToObject(cjs_Z7,	"val",	pattr_obj->config.thPowerHi ); 
        cJSON_AddItemToArray(cjs_attr_array,	cjs_Z7 );

        cJSON *cjs_Z8  = cJSON_CreateObject();				//创建一个对象   
        cJSON_AddStringToObject(cjs_Z8,	"name",	"thPowerLow" );
        cJSON_AddNumberToObject(cjs_Z8,	"val",	pattr_obj->config.thPowerLow ); 
        cJSON_AddItemToArray(cjs_attr_array,	cjs_Z8 );


        cJSON *cjs_Z9  = cJSON_CreateObject();				//创建一个对象   
        cJSON_AddStringToObject(cjs_Z9,	"name",	"thCurrHi" );
        cJSON_AddNumberToObject(cjs_Z9,	"val",	pattr_obj->config.thCurrHi ); 
        cJSON_AddItemToArray(cjs_attr_array,	cjs_Z9 );

        cJSON *cjs_Z10  = cJSON_CreateObject();				//创建一个对象   
        cJSON_AddStringToObject(cjs_Z10,	"name",	"thCurrLow" );
        cJSON_AddNumberToObject(cjs_Z10,	"val",	pattr_obj->config.thCurrLow ); 
        cJSON_AddItemToArray(cjs_attr_array,	cjs_Z10 );


#if 0 //   ?????-----避免误操作，导致电能清0，需要独立的电能清0指令    
    ///---------------------正向电能清0------------------------------------------------

            cJSON *cjs_Z3  = cJSON_CreateObject();				//创建一个对象            
            cJSON_AddStringToObject(cjs_Z3,	"name",	"rptEngT" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );

            sprintf(attr_val_str_buf,"%d",  pattr_obj->data.Energy);
            printf("attr_val=%d,attr_val_str=%s\n",  pattr_obj->data.Energy ,attr_val_str_buf);
            cJSON_AddStringToObject(cjs_Z3,	"val",	attr_val_str_buf  ); 

            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z3 );


    ///---------------------------------------------------------------------

    ///---------------------反向电能清0------------------------------------------------

            cJSON *cjs_Z4  = cJSON_CreateObject();				//创建一个对象            
            cJSON_AddStringToObject(cjs_Z4,	"name",	"rptRevEngT" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );

            sprintf(attr_val_str_buf,"%d",  pattr_obj->data.InvEnergy);
            printf("attr_val=%d,attr_val_str=%s\n",  pattr_obj->data.InvEnergy ,attr_val_str_buf);
            cJSON_AddStringToObject(cjs_Z4,	"val",	attr_val_str_buf  ); 

            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z4 );


///---------------------------------------------------------------------

#endif


        }break;



        case IOT_SENSOR_smoke:
        {     
            // 0x0620	alarmEn	烟雾报警使能
            // 0x0621	almDelay	报警延时时间

            smoke_attr_t*  pattr_obj=NULL;  
            pattr_obj = smoke_get_obj( index) ; 


            cJSON *cjs_Z0  = cJSON_CreateObject();				//创建一个对象     
            cJSON_AddStringToObject(cjs_Z0,	"name",	"alarmEn" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );

            sprintf(attr_val_str_buf,"%d",  pattr_obj->config.alarm_enable.value);
            printf("attr_val=%x,attr_val_str=%s\n", pattr_obj->config.alarm_enable.value,attr_val_str_buf);

            cJSON_AddStringToObject(cjs_Z0,	"val",	attr_val_str_buf ); 
            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z0 );


            cJSON *cjs_Z1  = cJSON_CreateObject();		   
            cJSON_AddStringToObject(cjs_Z1,	"name",	"almDelay" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );

            sprintf(attr_val_str_buf,"%d",  pattr_obj->config.alarm_delay_sec);
            printf("attr_val=%x,attr_val_str=%s\n", pattr_obj->config.alarm_delay_sec,attr_val_str_buf);

            cJSON_AddStringToObject(cjs_Z1,	"val",	attr_val_str_buf ); 
            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z1 );


        }break;



        case IOT_SENSOR_water:
        {
            dev_water_attr_t*   pattr_obj=NULL; 
            pattr_obj = dev_water_get_obj( index) ; 

// 0x0630	alarmEn	水浸报警使能
// 0x0631	simMode	sim工作方式
// 0x0632	thLeakIpd	泄露阻抗阈值
// 0x0633	thCurr	工作电流阈值
// 0x0634	thSensor	传感增量阈值
// 0x0635	resRate	电阻率

            cJSON *cjs_Z0  = cJSON_CreateObject();				//创建一个对象     
            cJSON_AddStringToObject(cjs_Z0,	"name",	"alarmEn" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );

            sprintf(attr_val_str_buf,"%d",  pattr_obj->config.alarm_enable.value);
            printf("attr_val=%x,attr_val_str=%s\n", pattr_obj->config.alarm_enable.value,attr_val_str_buf);

            cJSON_AddStringToObject(cjs_Z0,	"val",	attr_val_str_buf ); 
            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z0 );


            cJSON *cjs_Z1  = cJSON_CreateObject();		   
            cJSON_AddStringToObject(cjs_Z1,	"name",	"simMode" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );

            sprintf(attr_val_str_buf,"%d",  pattr_obj->config.mode);
            printf("attr_val=%x,attr_val_str=%s\n", pattr_obj->config.mode,attr_val_str_buf);

            cJSON_AddStringToObject(cjs_Z1,	"val",	attr_val_str_buf ); 
            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z1 );



            cJSON *cjs_Z2  = cJSON_CreateObject();		   
            cJSON_AddStringToObject(cjs_Z2,	"name",	"thLeakIpd" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );

            sprintf(attr_val_str_buf,"%d",  pattr_obj->config.leak_kohm_th);
            printf("attr_val=%x,attr_val_str=%s\n", pattr_obj->config.leak_kohm_th,attr_val_str_buf);

            cJSON_AddStringToObject(cjs_Z2,	"val",	attr_val_str_buf ); 
            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z2 );


            cJSON *cjs_Z3  = cJSON_CreateObject();		   
            cJSON_AddStringToObject(cjs_Z3,	"name",	"thCurr" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );

            sprintf(attr_val_str_buf,"%d",  pattr_obj->config.current_th);
            printf("attr_val=%x,attr_val_str=%s\n", pattr_obj->config.current_th,attr_val_str_buf);

            cJSON_AddStringToObject(cjs_Z3,	"val",	attr_val_str_buf ); 
            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z3 );


            cJSON *cjs_Z4  = cJSON_CreateObject();		   
            cJSON_AddStringToObject(cjs_Z4,	"name",	"thSensor" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );

            sprintf(attr_val_str_buf,"%d",  pattr_obj->config.inc_percent_th);
            printf("attr_val=%x,attr_val_str=%s\n", pattr_obj->config.inc_percent_th,attr_val_str_buf);

            cJSON_AddStringToObject(cjs_Z4,	"val",	attr_val_str_buf ); 
            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z4 );


            cJSON *cjs_Z5  = cJSON_CreateObject();		   
            cJSON_AddStringToObject(cjs_Z5,	"name",	"resRate" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );

            sprintf(attr_val_str_buf,"%d",  pattr_obj->config.wire_ohm_m);
            printf("attr_val=%x,attr_val_str=%s\n", pattr_obj->config.wire_ohm_m,attr_val_str_buf);

            cJSON_AddStringToObject(cjs_Z5,	"val",	attr_val_str_buf ); 
            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z5 );


        }break;


        case IOT_SENSOR_air_cond:
        {
            air_cond_attr_t*   pattr_obj=NULL; 
            pattr_obj = air_cond_get_obj(index) ; 

            cJSON *cjs_Z0  = cJSON_CreateObject();				//创建一个对象     
            cJSON_AddStringToObject(cjs_Z0,	"name",	"energySaveTempe" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );

            sprintf(attr_val_str_buf,"%d",  pattr_obj->config.energySaveTempe);
            printf("attr_val=%x,attr_val_str=%s\n", pattr_obj->config.energySaveTempe,attr_val_str_buf);

            cJSON_AddStringToObject(cjs_Z0,	"val",	attr_val_str_buf ); 
            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z0 );



            cJSON *cjs_Z1  = cJSON_CreateObject();		   
            cJSON_AddStringToObject(cjs_Z1,	"name",	"energySaveFanSpeed" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );

            sprintf(attr_val_str_buf,"%d",  pattr_obj->config.energySaveFanSpeed);
            printf("attr_val=%x,attr_val_str=%s\n", pattr_obj->config.energySaveFanSpeed,attr_val_str_buf);

            cJSON_AddStringToObject(cjs_Z1,	"val",	attr_val_str_buf ); 
            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z1 );



            cJSON *cjs_Z2  = cJSON_CreateObject();		   
            cJSON_AddStringToObject(cjs_Z2,	"name",	"acStatusDetectMode" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );

            sprintf(attr_val_str_buf,"%d",  pattr_obj->config.acStatusDetectMode);
            printf("attr_val=%x,attr_val_str=%s\n", pattr_obj->config.acStatusDetectMode,attr_val_str_buf);

            cJSON_AddStringToObject(cjs_Z2,	"val",	attr_val_str_buf ); 
            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z2 );



            cJSON *cjs_Z3  = cJSON_CreateObject();		   
            cJSON_AddStringToObject(cjs_Z3,	"name",	"DO" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );

            sprintf(attr_val_str_buf,"%d",  pattr_obj->config.DO);
            printf("attr_val=%x,attr_val_str=%s\n", pattr_obj->config.DO,attr_val_str_buf);

            cJSON_AddStringToObject(cjs_Z3,	"val",	attr_val_str_buf ); 
            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z3 );



            cJSON *cjs_Z4  = cJSON_CreateObject();		   
            cJSON_AddStringToObject(cjs_Z4,	"name",	"DI" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );

            sprintf(attr_val_str_buf,"%d",  pattr_obj->config.DI);
            printf("attr_val=%x,attr_val_str=%s\n", pattr_obj->config.DI,attr_val_str_buf);

            cJSON_AddStringToObject(cjs_Z4,	"val",	attr_val_str_buf ); 
            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z4 );



            cJSON *cjs_Z5  = cJSON_CreateObject();		   
            cJSON_AddStringToObject(cjs_Z5,	"name",	"doFuncSel" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );

            sprintf(attr_val_str_buf,"%d",  pattr_obj->config.doFuncSel);
            printf("attr_val=%x,attr_val_str=%s\n", pattr_obj->config.doFuncSel,attr_val_str_buf);

            cJSON_AddStringToObject(cjs_Z5,	"val",	attr_val_str_buf ); 
            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z5 );



            cJSON *cjs_Z6  = cJSON_CreateObject();		   
            cJSON_AddStringToObject(cjs_Z6,	"name",	"diFuncSel" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );

            sprintf(attr_val_str_buf,"%d",  pattr_obj->config.diFuncSel);
            printf("attr_val=%x,attr_val_str=%s\n", pattr_obj->config.diFuncSel,attr_val_str_buf);

            cJSON_AddStringToObject(cjs_Z6,	"val",	attr_val_str_buf ); 
            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z6 );


            cJSON *cjs_Z7  = cJSON_CreateObject();		   
            cJSON_AddStringToObject(cjs_Z7,	"name",	"diCtrlSel" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );

            sprintf(attr_val_str_buf,"%d",  pattr_obj->config.diCtrlSel);
            printf("attr_val=%x,attr_val_str=%s\n", pattr_obj->config.diCtrlSel,attr_val_str_buf);

            cJSON_AddStringToObject(cjs_Z7,	"val",	attr_val_str_buf ); 
            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z7 );



            cJSON *cjs_Z8  = cJSON_CreateObject();		   
            cJSON_AddStringToObject(cjs_Z8,	"name",	"pwrOnAutoStart" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );

            sprintf(attr_val_str_buf,"%d",  pattr_obj->config.pwrOnAutoStart);
            printf("attr_val=%x,attr_val_str=%s\n", pattr_obj->config.pwrOnAutoStart,attr_val_str_buf);

            cJSON_AddStringToObject(cjs_Z8,	"val",	attr_val_str_buf ); 
            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z8 );



            cJSON *cjs_Z9  = cJSON_CreateObject();		   
            cJSON_AddStringToObject(cjs_Z9,	"name",	"buzzerFunc" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );

            sprintf(attr_val_str_buf,"%d",  pattr_obj->config.buzzerFunc);
            printf("attr_val=%x,attr_val_str=%s\n", pattr_obj->config.buzzerFunc,attr_val_str_buf);

            cJSON_AddStringToObject(cjs_Z9,	"val",	attr_val_str_buf ); 
            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z9 );


            cJSON *cjs_Z10  = cJSON_CreateObject();		   
            cJSON_AddStringToObject(cjs_Z10,	"name",	"coolWarmMode" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );

            sprintf(attr_val_str_buf,"%d",  pattr_obj->config.coolWarmMode);
            printf("attr_val=%x,attr_val_str=%s\n", pattr_obj->config.coolWarmMode,attr_val_str_buf);

            cJSON_AddStringToObject(cjs_Z10,	"val",	attr_val_str_buf ); 
            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z10 );



            cJSON *cjs_Z11  = cJSON_CreateObject();		   
            cJSON_AddStringToObject(cjs_Z11,	"name",	"acStatusTH" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );

            sprintf(attr_val_str_buf,"%d",  pattr_obj->config.acStatusTH);
            printf("attr_val=%x,attr_val_str=%s\n", pattr_obj->config.acStatusTH,attr_val_str_buf);

            cJSON_AddStringToObject(cjs_Z11,	"val",	attr_val_str_buf ); 
            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z11 );


            cJSON *cjs_Z12  = cJSON_CreateObject();		   
            cJSON_AddStringToObject(cjs_Z12,	"name",	"acPwrOnOffTime" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );

            sprintf(attr_val_str_buf,"%d",  pattr_obj->config.acPwrOnOffTime);
            printf("attr_val=%x,attr_val_str=%s\n", pattr_obj->config.acPwrOnOffTime,attr_val_str_buf);

            cJSON_AddStringToObject(cjs_Z12,	"val",	attr_val_str_buf ); 
            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z12 );



            cJSON *cjs_Z13  = cJSON_CreateObject();		   
            cJSON_AddStringToObject(cjs_Z13,	"name",	"ctrlMode" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );

            sprintf(attr_val_str_buf,"%d",  pattr_obj->config.ctrlMode);
            printf("attr_val=%x,attr_val_str=%s\n", pattr_obj->config.ctrlMode,attr_val_str_buf);

            cJSON_AddStringToObject(cjs_Z13,	"val",	attr_val_str_buf ); 
            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z13 );


            cJSON *cjs_Z14  = cJSON_CreateObject();		   
            cJSON_AddStringToObject(cjs_Z14,	"name",	"diCtrlMinPwrOnTime" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );

            sprintf(attr_val_str_buf,"%d",  pattr_obj->config.diCtrlMinPwrOnTime);
            printf("attr_val=%x,attr_val_str=%s\n", pattr_obj->config.diCtrlMinPwrOnTime,attr_val_str_buf);

            cJSON_AddStringToObject(cjs_Z14,	"val",	attr_val_str_buf ); 
            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z14 );


            cJSON *cjs_Z15  = cJSON_CreateObject();		   
            cJSON_AddStringToObject(cjs_Z15,	"name",	"diCtrlMinTrigTime" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );

            sprintf(attr_val_str_buf,"%d",  pattr_obj->config.diCtrlMinTrigTime);
            printf("attr_val=%x,attr_val_str=%s\n", pattr_obj->config.diCtrlMinTrigTime,attr_val_str_buf);

            cJSON_AddStringToObject(cjs_Z15,	"val",	attr_val_str_buf ); 
            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z15 );


            cJSON *cjs_Z16  = cJSON_CreateObject();		   
            cJSON_AddStringToObject(cjs_Z16,	"name",	"teHuAlmTime" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );

            sprintf(attr_val_str_buf,"%d",  pattr_obj->config.teHuAlmTime);
            printf("attr_val=%x,attr_val_str=%s\n", pattr_obj->config.teHuAlmTime,attr_val_str_buf);

            cJSON_AddStringToObject(cjs_Z16,	"val",	attr_val_str_buf ); 
            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z16 );




            cJSON *cjs_Z17  = cJSON_CreateObject();		   
            cJSON_AddStringToObject(cjs_Z17,	"name",	"resetRecover" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );

            sprintf(attr_val_str_buf,"%d",  pattr_obj->config.resetRecover);
            printf("attr_val=%x,attr_val_str=%s\n", pattr_obj->config.resetRecover,attr_val_str_buf);

            cJSON_AddStringToObject(cjs_Z17,	"val",	attr_val_str_buf ); 
            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z17 );

            cJSON *cjs_Z18  = cJSON_CreateObject();		   
            cJSON_AddStringToObject(cjs_Z18,	"name",	"learnIr" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );

            sprintf(attr_val_str_buf,"%d",  pattr_obj->config.learnIr);
            printf("attr_val=%x,attr_val_str=%s\n", pattr_obj->config.learnIr,attr_val_str_buf);

            cJSON_AddStringToObject(cjs_Z18,	"val",	attr_val_str_buf ); 
            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z18 );




            cJSON *cjs_Z19  = cJSON_CreateObject();		   
            cJSON_AddStringToObject(cjs_Z19,	"name",	"sendIr" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );

            sprintf(attr_val_str_buf,"%d",  pattr_obj->config.sendIr);
            printf("attr_val=%x,attr_val_str=%s\n", pattr_obj->config.sendIr,attr_val_str_buf);

            cJSON_AddStringToObject(cjs_Z19,	"val",	attr_val_str_buf ); 
            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z19 );


            cJSON *cjs_Z20  = cJSON_CreateObject();		   
            cJSON_AddStringToObject(cjs_Z20,	"name",	"remoteCode" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );

            sprintf(attr_val_str_buf,"%d",  pattr_obj->config.remoteCode);
            printf("attr_val=%x,attr_val_str=%s\n", pattr_obj->config.remoteCode,attr_val_str_buf);

            cJSON_AddStringToObject(cjs_Z20,	"val",	attr_val_str_buf ); 
            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z20 );


            cJSON *cjs_Z21  = cJSON_CreateObject();		   
            cJSON_AddStringToObject(cjs_Z21,	"name",	"remoteCtrlKey" );

            memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );

            sprintf(attr_val_str_buf,"%d",  pattr_obj->config.remoteCtrlKey);
            printf("attr_val=%x,attr_val_str=%s\n", pattr_obj->config.remoteCtrlKey,attr_val_str_buf);

            cJSON_AddStringToObject(cjs_Z21,	"val",	attr_val_str_buf ); 
            cJSON_AddItemToArray(cjs_attr_array,	cjs_Z21 );

        }break;



        case IOT_SENSOR_battery:
        {
            IotModel iot_model_obj;
//           battery_attr_t*  pattr_obj=NULL;  
//           pattr_obj = battery_get_obj( index) ; 

            //cJSON *cjs_Z[battery_iot_id_key_name_table_mult_write_end] ;	
//-------------------------------------------------------------------------------------
           for(z_idx=0; z_idx<battery_iot_id_key_name_table_mult_write_end ;z_idx++)
           {
                cjs_Z[z_idx]  = cJSON_CreateObject();//创建一个对象     
                cJSON_AddStringToObject(cjs_Z[z_idx],	"name",	battery_iot_id_key_name_table[z_idx].name );
                battery_get_attr( index, battery_iot_id_key_name_table[z_idx].key,  &iot_model_obj);
                memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );
                sprintf(attr_val_str_buf,"%ld", iot_model_obj.value );

#if  IOT_SENSOR_battery_log_enable                                                                    
                log_debug("attr_val_str=%s\n",attr_val_str_buf);            
#endif           
                cJSON_AddStringToObject(cjs_Z[z_idx],	"val",	attr_val_str_buf ); 
                cJSON_AddItemToArray(cjs_attr_array,	cjs_Z[z_idx] );
          }
//-------------------------------------------------------------------------------------
        }break;



        case IOT_SENSOR_generator:
        {
            IotModel iot_model_obj;
           // cJSON *cjs_Z[generator_iot_id_key_name_table_mult_write_end] ;	
//-------------------------------------------------------------------------------------
           for(z_idx=0; z_idx<generator_iot_id_key_name_table_mult_write_end ;z_idx++)
           {
                cjs_Z[z_idx]  = cJSON_CreateObject();//创建一个对象     
                cJSON_AddStringToObject(cjs_Z[z_idx],	"name",	generator_iot_id_key_name_table[z_idx].name );
                generator_get_attr( index, generator_iot_id_key_name_table[z_idx].key,  &iot_model_obj);
                memset(attr_val_str_buf,0,ATTR_VAL_STR_BUF_MAX );
                sprintf(attr_val_str_buf,"%ld", iot_model_obj.value );

#if  IOT_SENSOR_generator_log_enable                                                                    
                log_debug("attr_val_str=%s\n",attr_val_str_buf);            
#endif           
                cJSON_AddStringToObject(cjs_Z[z_idx],	"val",	attr_val_str_buf ); 
                cJSON_AddItemToArray(cjs_attr_array,	cjs_Z[z_idx] );
          }
//-------------------------------------------------------------------------------------


        }break;



        default:
        {     
        }break;


    /////路灯电源节点
    ////lamp_set_attr( (IotModel*) attr_in);

   } ////---switch----------------



	cJSON_AddItemToObject(cjs_root,	"attrLst",	cjs_attr_array );	//对象



    //JSON数据结构转换为JSON字符串
#if CJSON_PRINT_UNFORM_ENABLE
	cjs_str = cJSON_PrintUnformatted(cjs_root);    //没有空格符的格式=====提高通信效率------
#else
	cjs_str = cJSON_Print(cjs_root);		         // 有空格符的格式------便于人工阅读识别-------------
#endif


    if (cjs_str == NULL)
    {
      	printf("cJSON_Print error!\n");	          
        goto lab_exit;
    }


#if CJSON_PRINT_ENABLE
	printf("%s\n",cjs_str);		//输出字符串
#endif		//输出字符串

	//send(cjs_str);      //发送数据

    //返回值 0---发送失败，1---发送成功
    gw_ktj_TCP_ClientSend( (uint8_t*)cjs_str, strlen(cjs_str) );


    //free(cjs_str );   //释放内存空间---尚未确定是否需要这步---????--
    cJSON_free(cjs_str ); 


    usleep(TLV_Write_wait_us); //等待写完成

lab_exit:

    if ( cjs_root != NULL)
    {
	    cJSON_Delete(cjs_root);		//清除结构体
    }

    cjs_root = NULL;  
    cjs_str = NULL;

 return 1;

}



// Tcp_Tx_ch=1, local_ktj_js
// {"head":{"gatewayId":"gw_CC0500CFB180","msgId":624,"timeStamp":0,"cmd":"setAttr"},
// "data":{"deviceName":"smoke_1_6","mac":"FFFFFFFFFFFF","nodeType":1,"channel":1,"privAddr":20},
// "attrLst":[{"dpid":1568,"val":1}]}
// iotv30  socket send done
// 17:50:12- ETH_1 local_ktj_js Rx: len=192
// {"head":{"gatewayId":"gw_CC0500CFB180","replaceId":"","msgId":624,"timeStamp":1740131412,"response":"setAttr"},
// "data":{"pid":"4007","mac":"FFFFFFFFFFFF","deviceName":"smoke_1_6"},
// "errCode":0}


// Tcp_Tx_ch=1, local_ktj_js
// {"head":{"gatewayId":"gw_CC0500CFB180","msgId":626,"timeStamp":0,"cmd":"setAttr"},
// "data":{"deviceName":"smoke_1_6","mac":"FFFFFFFFFFFF","nodeType":1,"channel":1,"privAddr":20},
// "attrLst":[{"dpid":1569,"val":25}]}
// iotv30  socket send done
// 17:50:13- ETH_1 local_ktj_js Rx: len=155
// {"head":{"gatewayId":"gw_CC0500CFB180","replaceId":"","msgId":626,"timeStamp":1740131413,"response":"setAttr"},
// "errcode":45,"reason":"SOME_PARAM_SET_ERR"}


 //一次只写一个iot_id对应的配置参数-------json 协议参数用的是 dpid------
uint8_t json_write_setAttr_dev_config_one_with_pdip(const uint8_t index, const uint8_t seq,dev_mod_info_t* info,void* iot_model )
{
    cJSON* cjs_root = NULL;  
    cJSON* cjs_data = NULL;
    cJSON* cjs_attr_array = NULL;
 //   cJSON* cjs_item = NULL;    
    char*  cjs_str  = NULL;
    IotModel* piot_model= NULL;

#define   ATTR_VAL_STR_BUF_MAX       (32u)

 char name_str_buf[ATTR_VAL_STR_BUF_MAX];


  LOG_NAME();



  if (iot_model == NULL)
  {
      goto lab_exit;
  }

  piot_model= (IotModel*)iot_model;



  // char gatewayId_str[]="010000000780";
	
	cjs_root = cJSON_CreateObject();   //创建一个对象
    if (cjs_root == NULL)
    {
        goto lab_exit;
    }


	cjs_data = cJSON_CreateObject();   //创建一个对象data
    if (cjs_data == NULL)
    {
        goto lab_exit;
    }



// 	"head": {
// 		"gatewayId": "gw_1C32830600E6",
// 		"msgId": 0,
// 		"timeStamp": 0,
// 		"cmd": "setAttr",
// 		"appuserId": 27                //  可以不要
// 	}
// }


	if(  0==set_json_comm_item(cjs_root, TYPE_CMD, "setAttr", seq) )  //gui_js_api_msg_id++
    {
        goto lab_exit;     
    }



// {
// 	"data": {
// 		"deviceName": "oilLevel_2_1",
// 		"mac": "FFFFFFFFFFFF",
// 		"nodeType": 1,
// 		"channel": 1,
// 		"privAddr": 1
// 	},


    if(NULL !=info->pdev_name_str)
    {
        memset(name_str_buf,0, sizeof(name_str_buf) );
        strncpy(name_str_buf, info->pdev_name_str, sizeof(name_str_buf) );
        logout("name_str_buf=%s", name_str_buf);
        cJSON_AddStringToObject(cjs_data,	"deviceName",	name_str_buf );//dev_name=eleMeter_1_5
       // cJSON_AddStringToObject(cjs_data,	"deviceName",	"eleMeter_1_5" );
    }
	

   // if(NULL !=node_mac)
    {
        cJSON_AddStringToObject(cjs_data,	"mac",	"FFFFFFFFFFFF" );
    }
	
	
    if(NULL !=info)
    {
        cJSON_AddNumberToObject(cjs_data,	"nodeType",	1);//info->node_type-----固定为1
        cJSON_AddNumberToObject(cjs_data,	"channel",	info->channel );        
        cJSON_AddNumberToObject(cjs_data,	"privAddr",	info->chan_addr );    
    }
	

	cJSON_AddItemToObject(cjs_root,	"data",	cjs_data );	//对象


// 	"attrLst": [{
// 		"name": "thTH",
// 		"lable": "温度过高阈值",    //  可以不要
// 		"val": "98",
// 		"order": 1                //  可以不要
// 	}],



	cjs_attr_array  = cJSON_CreateArray();				//创建一个数组
    if (cjs_attr_array == NULL)
    {
        goto lab_exit;
    }


//{"head":{"gatewayId":"gw_1C32830085B0","cmd":"setAttr"},"data":{"deviceName":"airCond_1_1"},"attrLst":[{"name":"sendIr","val":277}]}
//{"head":{"gatewayId":"gw_1C32830085B0","cmd":"setAttr"},"data":{"deviceName":"airCond_1_1"},"attrLst":[{"dpid":2349,"val":0}]}

    cJSON *cjs_Z0  = cJSON_CreateObject();				//创建一个对象     

	cJSON_AddNumberToObject(cjs_Z0, "dpid", piot_model->iot_id );
	cJSON_AddNumberToObject(cjs_Z0, "val", piot_model->value );

    cJSON_AddItemToArray(cjs_attr_array,	cjs_Z0 );

	cJSON_AddItemToObject(cjs_root,	"attrLst",	cjs_attr_array );	//对象



    //JSON数据结构转换为JSON字符串
#if CJSON_PRINT_UNFORM_ENABLE
	cjs_str = cJSON_PrintUnformatted(cjs_root);    //没有空格符的格式=====提高通信效率------
#else
	cjs_str = cJSON_Print(cjs_root);		         // 有空格符的格式------便于人工阅读识别-------------
#endif


    if (cjs_str == NULL)
    {
      	printf("cJSON_Print error!\n");	          
        goto lab_exit;
    }


#if CJSON_PRINT_ENABLE
	printf("%s\n",cjs_str);		//输出字符串
#endif		//输出字符串

	//send(cjs_str);      //发送数据

    //返回值 0---发送失败，1---发送成功
    gw_ktj_TCP_ClientSend( (uint8_t*)cjs_str, strlen(cjs_str) );


    //free(cjs_str );   //释放内存空间---尚未确定是否需要这步---????--
    cJSON_free(cjs_str ); 



    usleep(TLV_Write_one_wait_us); //等待写完成

lab_exit:

    if ( cjs_root != NULL)
    {
	    cJSON_Delete(cjs_root);		//清除结构体
    }

    cjs_root = NULL;  
    cjs_str = NULL;

 return 1;

}







 //一次只写一个iot_id对应的配置参数-------json 协议参数用的是 dpid------
 uint8_t json_write_setAttr_dev_config_all_with_pdip(const uint8_t index, const uint8_t seq,dev_mod_info_t* info )
 {
     cJSON* cjs_root = NULL;  
     cJSON* cjs_data = NULL;
     cJSON* cjs_attr_array = NULL;
  //   cJSON* cjs_item = NULL;    
     char*  cjs_str  = NULL;
    // IotModel* piot_model= NULL;
 
 #define   ATTR_VAL_STR_BUF_MAX       (32u)
 
  char name_str_buf[ATTR_VAL_STR_BUF_MAX];
 
 
   LOG_NAME();
 
 
   // char gatewayId_str[]="010000000780";
     
     cjs_root = cJSON_CreateObject();   //创建一个对象
     if (cjs_root == NULL)
     {
         goto lab_exit;
     }
 
 
     cjs_data = cJSON_CreateObject();   //创建一个对象data
     if (cjs_data == NULL)
     {
         goto lab_exit;
     }
 
 
 
 // 	"head": {
 // 		"gatewayId": "gw_1C32830600E6",
 // 		"msgId": 0,
 // 		"timeStamp": 0,
 // 		"cmd": "setAttr",
 // 		"appuserId": 27                //  可以不要
 // 	}
 // }
 
 
     if(  0==set_json_comm_item(cjs_root, TYPE_CMD, "setAttr",  seq ) )   //gui_js_api_msg_id++
     {
         goto lab_exit;     
     }
 
 
 
 // {
 // 	"data": {
 // 		"deviceName": "oilLevel_2_1",
 // 		"mac": "FFFFFFFFFFFF",
 // 		"nodeType": 1,
 // 		"channel": 1,
 // 		"privAddr": 1
 // 	},
 
 
     if(NULL !=info->pdev_name_str)
     {
         memset(name_str_buf,0, sizeof(name_str_buf) );
         strncpy(name_str_buf, info->pdev_name_str, sizeof(name_str_buf) );
         logout("name_str_buf=%s", name_str_buf);
         cJSON_AddStringToObject(cjs_data,	"deviceName",	name_str_buf );//dev_name=eleMeter_1_5
        // cJSON_AddStringToObject(cjs_data,	"deviceName",	"eleMeter_1_5" );
     }
     
 
    // if(NULL !=node_mac)
     {
         cJSON_AddStringToObject(cjs_data,	"mac",	"FFFFFFFFFFFF" );
     }
     
     
     if(NULL !=info)
     {
         cJSON_AddNumberToObject(cjs_data,	"nodeType",	1);//info->node_type-----固定为1
         cJSON_AddNumberToObject(cjs_data,	"channel",	info->channel );        
         cJSON_AddNumberToObject(cjs_data,	"privAddr",	info->chan_addr );    
     }
     
 
     cJSON_AddItemToObject(cjs_root,	"data",	cjs_data );	//对象
 
 
 // 	"attrLst": [{
 // 		"name": "thTH",
 // 		"lable": "温度过高阈值",    //  可以不要
 // 		"val": "98",
 // 		"order": 1                //  可以不要
 // 	}],
 
 
 
     cjs_attr_array  = cJSON_CreateArray();				//创建一个数组
     if (cjs_attr_array == NULL)
     {
         goto lab_exit;
     }
 
 
 //{"head":{"gatewayId":"gw_1C32830085B0","cmd":"setAttr"},"data":{"deviceName":"airCond_1_1"},"attrLst":[{"name":"sendIr","val":277}]}
 //{"head":{"gatewayId":"gw_1C32830085B0","cmd":"setAttr"},"data":{"deviceName":"airCond_1_1"},"attrLst":[{"dpid":2349,"val":0}]}
   
         IotModel iot_model_obj;

         cJSON *cjs_Z[IOT_ID_TABLE_MAX] ;	


         uint8_t  len = dev_module_get_config_data_len( info->node_type ) ; 

         uint16_t*  ptable =  dev_module_get_config_table( info->node_type ) ; 

 
        //-------------------------------------------------------------------------------------
            for(uint8_t z_idx=0; z_idx<len ;z_idx++)
            {
                cjs_Z[z_idx]  = cJSON_CreateObject();//创建一个对象     

                // battery_get_attr( index, battery_iot_id_key_name_table[z_idx].key,  &iot_model_obj);
                // cJSON_AddStringToObject(cjs_Z[z_idx],	"name",	battery_iot_id_key_name_table[z_idx].name );   


                dev_module_get_attr( index, ptable[z_idx],  &iot_model_obj);
        
                cJSON_AddNumberToObject(cjs_Z[z_idx], "dpid", iot_model_obj.iot_id );   
                cJSON_AddNumberToObject(cjs_Z[z_idx], "val", iot_model_obj.value );
                cJSON_AddItemToArray(cjs_attr_array,	cjs_Z[z_idx] );
            }
        //-------------------------------------------------------------------------------------
                
/*-----------------------------------------------------------------------------------
        iot_find_node_index_with_sub_uid
        found sub_uid=5,indx=0
        iot_get_mod_info_with_index
        got info:indx=0, chan_addr=1,channel=1,node_type=d000,dev_name=0xd3f4f
        set addr 0610, value = 7
        set addr 0611, value = 2500
        set addr 0612, value = 7700
        set addr 0606, value = 1200
        set addr 0607, value = 3600
        json_write_setAttr_dev_config_all_with_pdip
        name_str_buf=tempe_1_3{"head":{"gatewayId":"gw_CC0500CFB180","msgId":69,"cmd":"setAttr"},"data":{"deviceName":"tempe_1_3","mac":"FFFFFFFFFFFF","nodeType":1,"channel":1,"privAddr":1},"attrLst":[{"dpid":1536,"val":0},{"dpid":1538,"val":0},{"dpid":1542,"val":1200},{"dpid":1543,"val":3600},{"dpid":1552,"val":7},{"dpid":1553,"val":2500},{"dpid":1554,"val":7700},{"dpid":1555,"val":0},{"dpid":1556,"val":0},{"dpid":1557,"val":0},{"dpid":1558,"val":0}]}
        15:51:51-TCP_API_Send_Now


        name_str_buf=tempe_1_3{"head":
            {"gatewayId":"gw_CC0500CFB180",
            "msgId":69,"cmd":"setAttr"},"data":
            {"deviceName":"tempe_1_3",
            "mac":"FFFFFFFFFFFF",
            "nodeType":1,"channel":1,"privAddr":1},
            "attrLst":[
            {"dpid":1536,"val":0},
            {"dpid":1538,"val":0},
            {"dpid":1542,"val":1200},
            {"dpid":1543,"val":3600},
            {"dpid":1552,"val":7},
            {"dpid":1553,"val":2500},
            {"dpid":1554,"val":7700},
            {"dpid":1555,"val":0},
            {"dpid":1556,"val":0},
            {"dpid":1557,"val":0},
            {"dpid":1558,"val":0}]}
            15:51:51-TCP_API_Send_Now
            Tcp_TxData[1].Buff=0xd36f2,pdata=0x3fe8002510,len= 426

 ---------------------------------------------------------------------------------*/



        cJSON_AddItemToObject(cjs_root,	"attrLst",	cjs_attr_array );	//对象
 
 


     //JSON数据结构转换为JSON字符串
 #if CJSON_PRINT_UNFORM_ENABLE
     cjs_str = cJSON_PrintUnformatted(cjs_root);    //没有空格符的格式=====提高通信效率------
 #else
     cjs_str = cJSON_Print(cjs_root);		         // 有空格符的格式------便于人工阅读识别-------------
 #endif

 
     if (cjs_str == NULL)
     {
           printf("cJSON_Print error!\n");	          
         goto lab_exit;
     }
 
 
#if CJSON_PRINT_ENABLE
	printf("%s\n",cjs_str);		//输出字符串
#endif		//输出字符串
 
     //send(cjs_str);      //发送数据
 
     //返回值 0---发送失败，1---发送成功
     gw_ktj_TCP_ClientSend( (uint8_t*)cjs_str, strlen(cjs_str) );
 
 
    // free(cjs_str );   //释放内存空间---尚未确定是否需要这步---????--
     cJSON_free(cjs_str ); 


     usleep(TLV_Write_one_wait_us); //等待写完成
 
 lab_exit:
 
     if ( cjs_root != NULL)
     {
         cJSON_Delete(cjs_root);		//清除结构体
     }
 
     cjs_root = NULL;  
     cjs_str = NULL;
 
  return 1;
 
 }
 
 
 








// 下行：
// {
//    “head”:{
//        ..........
//        “cmd”:”readAttr”
// },
// “data”: { 
//     “groupName”:”lunchGroup”,
// }
// }

    //读多个设备的属性
void json_readAttr_group(uint8_t dev_addr, uint8_t channel,uint8_t nodeType )
{


}












